I have a parent shell html file that has an icon to update the number of products in the cart. The number is supposed to be retrieved from a factory.
angular
.module('awesome')
.factory('ProductFactory', productFactory);
function productFactory($log) {
var factory = {
addCartProducts: addCartProducts,
getCartCount: getCartCount
},
cartProducts = [];
return factory;
function addCartProducts(product)
{
cartProducts.push(product);
getCartCount();
$log.info(cartProducts.length);
}
function getCartCount() {
return cartProducts.length;
}
}
In the parent controller I have an scope
value being pulled from
$scope.count = ProductFactory.getCartCount()
In the child controller I'm adding to the cart
$scope.addToCart = function (product) {
ProductFactory.addCartProducts(product);
};
However when I add to the cart, I can see in the log that they are being added, however, the item in the parent controller does not update. What am I missing?