【发布时间】:2018-02-11 22:26:06
【问题描述】:
我想监视 max,如果 max 的值发生变化,那么它应该提醒
<div ng-controller='MyController' ng-app="myApp">
<div>{{title}}</div>
<input id='txt' type='text' max="{{max}}" value="{{max}}" foo/>
<input type="button" ng-click="changeMax()" value='change max' />
scope: {
max: '@',
},
link: function(scope, element, attrs) {
/*scope.$watch(attrs.max, function() {
alert('max changed to ' + max);
});*/
attrs.$observe('max', function(val) {
alert('max changed to ' + max);
});
}
我不知道我在做什么错误。我尝试了 $watch 和 $observe 但没有成功。 请任何人都可以提供帮助。
【问题讨论】:
标签: javascript angularjs angularjs-directive angularjs-watch