How to $watch changes on models created by ng-repeat?

后端 未结 6 1981
感动是毒
感动是毒 2020-12-08 00:53

Consider this Plnkr for example. I don\'t know how many members of fooCollection will be created beforehand. So I don\'t know how many bar models a

6条回答
  •  清歌不尽
    2020-12-08 01:14

    If you have your collection populated, you can place a watch on each item of the ng-repeat:

    html

    {{ item.itemField }}

    js

    for (var i = 0; i < $scope.items.length; i++) {
       $scope.$watch('items[' + i + ']', function (newValue, oldValue) {
          console.log(newValue.itemField + ":::" + oldValue.itemField);
       }, true);
    }
    

提交回复
热议问题