我有这个相当简单的 HTML 结构:
<div ng-controller="MyCtrl">
<div dir1="xy"><div>dir1static</div><div ng-repeat="item in items">dir1</div></div>
<div dir2="xy"><div>dir2static</div><div ng-repeat="item in items">dir2</div></div>
</div>
还有两个指令,其中一个 (dir2) 具有绑定到范围的属性:
myApp.directive("dir1", function () {
return {
restrict: "A",
link: function (scope, element, attributes) {
}
};
});
myApp.directive("dir2", function () {
return {
restrict: "A",
scope: {
dir2: "="
},
link: function (scope, element, attributes) {
}
};
});
使用以下控制器:
function MyCtrl($scope) {
$scope.xy = 2;
$scope.items = [1,2,3];
}
导致此输出:
dir1static
dir1
dir1
dir1
dir2static
因此,本质上,使用第二个指令时不会呈现 ng-repeat 部分。这有什么合乎逻辑的解释吗?