AngularJS watch array of objects for data change

后端 未结 3 1306
时光说笑
时光说笑 2020-11-30 05:27

I\'m implementing a shopping cart and want to store the data in localStorage. I want to watch the variable $scope.cart for change so that I can update the local

3条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 06:01

    $watch only evaluate string or function parameter in its first argument. Change your $watch like this :

    $scope.$watch('cart.name + cart.id + cart.amount', $scope.updateCart());
    

    OR

    $scope.$watch('cart', $scope.updateCart, true);
    

    See reference API

提交回复
热议问题