Cra*_*gan 5 javascript angularjs angularjs-directive
我把这个问题分解成了最简单的形式.基本上我有一个指令,对于演示,还没有真正做任何事情.我有一个div作为属性的指令.div中的值(来自对象数组)不会显示.如果我从div中删除指令,它们会显示OK.我显然遗漏了一些非常明显的东西,因为我之前没有遇到任何问题.
这是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: "="
}
};
});
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
有一个技巧可以通过使用 使其在早期版本的 Angular 中工作transclusion
,如下所示:
app.directive("cmTooltip", function () {
return {
scope: {
cmTooltip: "="
},
transclude: true,
template : '<div ng-transclude></div>'
};
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
84 次 |
最近记录: |