Hello guys!
I’m trying to change the items into de sidebar shopping cart from a controller. The items in the angularjs array is changed (I can see it in console) but the sidebar view with the ng-repeat is not refreshing.
I’ve tried disabling the ionic cache. You can check this example where the problem persist.
Thank you very much!
You are declaring the controller on both views, so $scope.items
is defined separately for the menu and the page. If you log $scope.items
after the declaration you’ll see it is logged twice. See this codepen: http://codepen.io/brandyshea/pen/yyZmab?editors=101
If you remove the controller from here, it fixes your problem, but I don’t know what the rest of your code is like:
'menuContent': {
templateUrl: "templates/main.html" ,
controller: 'AppCtrl'
}
2 Likes
Thank you very much!!
I forgot that concept. Maybe thats the problem with my app because I’ve the controller defined in all the views (even when is part of another view).
This really help me, thanks!!
1 Like
Hi,
Some suggestions, it is better to make your controller cleaner, and define a service to manage your shopping cart, something like this will be more useful:
angular.module(...)
.service('ShoppingCartService', function () {
// private variable, keep the data of shopping cart
var shoppingCart = [];
var service = {
// The interface you want to expose
add: function (item) {
shoppingCart.push(item);
},
drop: function () {},
update: function () {},
...
};
return service;
});
Best
2 Likes
Hello!
Yes, my real app uses services to communicate the shopping cart with the UI controllers. I wrote this little app only to explain my problem.
Finally is completely resolved in the real App.
Thanks!
2 Likes