为什么$ scope.watch无法使用'model'? http://jsfiddle.net/lesouthern/8PUtP/5/
.directive('testDirective',function() {
return {
restrict : 'A',
scope : {
model : '=ngModel'
},
link : function($scope,$element,$attrs) {
$scope.$watch('model',function(x) {
console.log('this is model: ' + x);
});
}
}
});
答案 0 :(得分:1)
请参阅this question。这是您更正后的代码:
return {
restrict : 'A',
link : function($scope, $element, $attrs) {
$scope.$watch($attrs.ngModel, function(x) {
console.log('this is model: ' + x);
});
}
}