[英]Calling $observe inside link function not working AngularJS (v1.0.8)
return {
restrict: 'AE',
controller: 'myAwesomeCtrl',
templateUrl: '/myAwesome.html',
replace: true,
link: function (scope, element, attrs) {
attrs.$observe('attributeName', function (x) {
scope.setAttrName(x);
});
}
};
Declared inside an ng-repeat and ng-switch: 在ng-repeat和ng-switch内部声明:
<div ng-repeat="f in fs">
<div ng-switch on="f.Name">
<myDirective attribute-name="{{f.AttributeName}}" ng-switch-when="thisIsTrue"></myDirective>
</div>
</div>
And amazingly, it does interpolate {{f.AttributeName}} correctly if I access $attrs from the directive's controller. 令人惊讶的是,如果我从指令的控制器访问$ attrs,它确实可以正确地插入{{f.AttributeName}}。
$attrs.$observe('attributeName', function (x) {
$scope.setAttrName(x); // value of x is 'TheValue'
});
This can't be expected behavior, can it? 这是无法预期的行为,可以吗? v1.0.8 v1.0.8
EDIT: I just confirmed it has nothing to do with ng-switch or ng-repeat... It is not working even if the directive is just by itself. 编辑:我只是确认它与ng-switch或ng-repeat没有关系...即使指令本身就是行不通的。
HERE IS THE PLUNKER: http://plnkr.co/edit/p46zuYbFAFCYH394zrUY?p=preview 此处是朋客: http ://plnkr.co/edit/p46zuYbFAFCYH394zrUY?p=preview
It's a bug, I filed it with the angular team. 这是一个错误,我将其提交给了角度小组。 I am working on fixing the issue and will submit a pull request. 我正在解决此问题,并将提交请求请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.