I am using AngularJs and ngStorage to make a shopping cart. I want to keep data in local storage. When I add something from different browser tab I want to call my http method in the cart where cart is opened. I wanted to use $scope.$watch but it is not working :(
I was trying als to use helper value in localstorage, first controller:
$scope.$watch('counter', function(newValue, oldValue) {
if(newValue === oldValue){
return;
}
console.log(newValue);
});
$scope.deleteItem = function (item) {
var index = $scope.storage.products.indexOf(item);
$scope.storage.products.splice(index, 1);
$scope.counter = 0;
}
Second Controller: $scope.addToCart = function(code) {
var prod = {
code: code,
quantity: 1,
color: 0,
notes: '',
};
$scope.storage.products.push(prod);
$scope.storage.counter=$scope.storage.counter+1;
$scope.$apply();
}
How to observe/watch my localstorage value when it is modified in another browser tab?