我试图获取指令内部的值何时从外部更改,并且它似乎不适用于 scope.$watch 或 attrs.$observe。
我这里有一把小提琴。
angular.module('zippyModule', [])
.directive('elem', function(){
return {
restrict: 'E',
transclude:true,
template:"Directive: <span ng-repeat='i in values'>{{i}} </span>",
scope: { values:'=zippyTitle' },
link: function(scope, element, attrs) {
attrs.$observe ('zippyTitle',function(newValue){
console.log (scope.values);
});
scope.$watch ('values',function(newValue){
console.log (scope.values);
});
}
}
});