Im building a cart in angular JS. It works like this user clicks on item function addToCart adds it to database
then on te page i have a cart wich displays cart contents. So in addToCart method i update cart.. and want to show the data.
The strange thing is that the $scope.cart shows all the objects in console... so all works fine... but on the view page the {{cart}} var shows only [] and it will not get updated... normaly every var updates automaticly but for some reason this one will not:
controller (stripped down)
c2App.controller('MakeOrderController', function($scope, $rootScope, $http, $location, $routeParams, ShareData, ngDialog) {
//there are more cvars here ... but those are not important
$scope.cart = [];
$scope.addToCart = function() {
$http({
url: "http://localhost/c2api/addtocart",
method: 'POST',
data:
{
'sessionid' : $rootScope.sessionid,
'menuId' : $scope.menuid,
'catId' : $scope.catid,
'resId' : $scope.resid,
'singleCat' : $scope.singleCat,
'multiCat' : $scope.multiCat,
'singleMenu' : $scope.singleMenu,
'multiMenu' : $scope.multiMenu,
'qty' : $scope.qty
},
headers : {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'}
}).success(function(data){
//update the cart
$scope.getCart($rootScope.sessionid,$scope.resid);
}).error(function(err){"ERR", console.log(err)});
};
$scope.getCart = function (ses,resid) {
if (!angular.isUndefined(ses) && !angular.isUndefined(resid)) {
$http({
url: "http://localhost/c2api/getcart",
method: 'GET',
params: {resId: resid, ses: ses},
headers : {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'}
}).success(function(data){
//SET CART DATA
$scope.cart = data;
console.log($scope.cart);// <--- THIS SHOWS ALL DATA!
}).error(function(err){"ERR", console.log(err)});
} else {
console.log('error.....');
}
}
});
and on the view:
<div id="collapseCart" class="slideable">
<div class="panel-body" style="background:#f8f8f8">
{{cart}}
</div>
when i put some var in the $scope.cart on load... it does show this on the view.. so for some reason it will not update
//UPDATE when i use $rootScope.cart = data and show {{$root.cart}} ... the data does show.....