【发布时间】:2017-10-12 00:07:03
【问题描述】:
我用下面的代码写了一个指令watchId
.directive('watchId', function(){
return {
restrict: 'A',
link: function(scope, elem, attr) {
scope.$watch(function() { return elem.attr('id') }, function(newValue){
if (newValue) {
scope.loaded[newValue] = true
}
})
}
}
})
上面的代码可以正常工作,但我的问题是为什么我不能只做scope.$watch(elem.attr('id'), function(newValue) {
我认为不需要它,但这里有一个JSfiddle,我在上面玩。
【问题讨论】:
标签: javascript angularjs angular2-directives