【发布时间】:2014-06-02 17:43:09
【问题描述】:
我注意到我的角度控制器正在增长,并且一直在尝试重构和使用指令和服务。
但是,在一种情况下,我正在尝试创建一个在 plunker 中似乎运行良好的指令,但是我在本地应用程序和 jsFiddle 中看到以下错误:
Error: [$compile:tplrt] http://errors.angularjs.org/1.2.8/$compile/tplrt?p0=getEmptyCells&p1=
Plunker 链接:http://plnkr.co/edit/e11zA8LKvoPTgTqW2HEE?p=preview
jsFiddle 链接(在 Firebug 中可以看到错误):http://jsfiddle.net/oampz/8hQ3R/14/
指令:
app.directive('getEmptyCells', function () {
return {
restrict: 'EA',
replace: true,
template: '<td ng-repeat="emptyCell in getEmptyCells(payments.Details.length)" class="empty">No Payment</td>',
scope: {
'payments' : '=getEmptyCells'
},
link: function (scope, elem, attr) {
scope.getEmptyCells = function (len) {
var emptyCells = [];
for (var i = 0; i < 12 - len; i++) {
emptyCells.push(i);
}
return emptyCells;
};
}
};
});
HTML:
<table>
<tr>With Directive:</tr>
<tr ng-repeat="payments in MyPayments">
<th>{{payments.name}}</th>
<td ng-repeat="paymentAmount in payments.Details.slice(0, 12)">{{ paymentAmount }}</td>
<td get-empty-cells="payments"></td>
</tr>
</table>
当我删除时:
template: '<td ng-repeat="emptyCell in getEmptyCells(payments.Details.length)" class="empty">No Payment</td>',
错误消失了,但自然不会产生预期的功能/输出。
我对可能导致这种情况的原因感到困惑。
【问题讨论】:
标签: angularjs angularjs-directive angularjs-scope angularjs-ng-repeat