我已将此问题分解为最简单的形式。基本上我有一个指令,对于演示,还没有真正做任何事情。我有一个将指令作为属性的 div。 div 中来自对象数组的值不会显示。如果我从 div 中删除指令,它们将显示为正常。我显然在这里遗漏了一些非常明显的东西,因为我之前没有任何问题地做过。
这是 Plunk:http://plnkr.co/edit/ZUXD4qW5hXvB7y9RG6sB?p=preview
脚本:
app.controller('MainCtrl', function($scope) {
$scope.tooltips = [{"id":1,"warn":true},{"id":2,"warn":false},{"id":3,"warn":true},{"id":4,"warn":true}];
});
app.directive("cmTooltip", function () {
return {
scope: {
cmTooltip: "="
}
};
});
HTML
<div ng-repeat="tip in tooltips" class="titlecell" cm-tooltip="true">
A div element: {{ tip.id }}
</div>
<br><br>
Just to prove it works without the directive:
<div ng-repeat="tip in tooltips" class="titlecell">
A div element: {{ tip.id }}
</div>
最佳答案
有一个 hack 可以通过使用 transclusion
使其在早期版本的 angular 中工作,就像这样:
app.directive("cmTooltip", function () {
return {
scope: {
cmTooltip: "="
},
transclude: true,
template : '<div ng-transclude></div>'
};
});
关于javascript - 来自指令的数据未在 ng-repeat 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20610172/