0
    return {
        restrict: 'AE',
        controller: 'myAwesomeCtrl',
        templateUrl: '/myAwesome.html',
        replace: true,
        link: function (scope, element, attrs) {
            attrs.$observe('attributeName', function (x) {
                scope.setAttrName(x);
            });
        }
    };

在 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>

令人惊讶的是,如果我从指令的控制器访问 $attrs,它确实会正确插入 {{f.AttributeName}}。

    $attrs.$observe('attributeName', function (x) {
        $scope.setAttrName(x);  // value of x is 'TheValue'
    });

这不能是预期的行为,可以吗?v1.0.8

编辑:我刚刚确认它与 ng-switch 或 ng-repeat 无关......即使指令本身也不起作用。

这是塞子: http ://plnkr.co/edit/p46zuYbFAFCYH394zrUY?p=preview

4

1 回答 1

1

这是一个错误,我向 Angular 团队提交了它。我正在努力解决这个问题,并将提交一个拉取请求。

于 2013-10-27T14:25:32.330 回答