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

后端 未结 6 1983
感动是毒
感动是毒 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:34

    Create individual list-item controllers: demo on Plnkr

    js

    angular
      .module('testApp', [])
      .controller('testCtrl', function ($scope) {
        $scope.fooCollection = [];
      })
      .controller('fooCtrl', function ($scope) {
        $scope.$watch('foo.bar', function (newValue, oldValue) {
          console.log('watch fired, new value: ' + newValue);
        });
      });
    

    HTML

    
      
        
    Tell me your name:
    Hello, my name is {{ foo.bar }}

提交回复
热议问题