我将数组中的用户名设置为不同的对象,并且我试图在指令中监听名称的更改。因此,当我在文本中输入任何内容时,模型会发生变化,那么为什么名称更改时不会发生$ watch fire?
JS
var app = angular.module('plunker', []);
app.directive('mydirective', function() {
return {
link : function(scope, elem, attr, ctrl) {
scope.$watch(scope.obj.users , function(newValue) {
console.log(scope.obj)
},true)
}
}
});
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.obj = {
"users" : [
{
'name' : 'user1'
},
{
'name' : 'user2'
}
]
}
});
HTML
<div ng-repeat="user in obj.users">
<input mydirective type="text" ng-model="user.name"/>
</div>