本地项目的jsfiddle,但在Plunker做工精细的角度编译模板错误 [英] Angular compile template error on local project and jsFiddle, but working fine in Plunker

查看:324
本文介绍了本地项目的jsfiddle,但在Plunker做工精细的角度编译模板错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现我的角度控制器正在增长,一直在试图重构并使用指令和服务。

I've noticed my angular controller is growing and have been trying to refactor and use directives and services.

然而,在一个场景中,我试图创建一个出现在plunker工作正常指令,但是我看到下面的错误在我的本地应用程序和的jsfiddle:

However, on one scenario, i am trying to create a directive which appears to be working fine in plunker, however i am seeing the following error in my local application and in 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 /

jsFiddle link (error can be seen in 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>',

的误差消失,但是自然的预期功能/输出不会产生

The error disappears, however naturally the expected functionality/output will not be produced.

我很困惑在什么可能导致此。

I'm confused at to what could cause this.

推荐答案

我当回事,以为它是的jsfiddle产生了一个问题。喜欢的jsfiddle或plunker任何服务都会有麻烦模拟一个真实的设置,同时还提供例如嵌入式输出,外部文件加载等一些解决方案似乎只是工作比别人更好的功能,而我一直的jsfiddle的爱心用户长时间 - AngularJS项目似乎只是工作很多plunker更好,尤其是与角模板,你可以在启动时选择。

I seriously think that it is a problem that jsfiddle creates. Any service like jsfiddle or plunker will have trouble emulating a real setup while still providing features like embedded output, external file loading etc. Some solutions just seem to work better than others, and while i've been a loving user of jsfiddle for long - AngularJS projects just seem to work a lot better in plunker, especially with the angular template you can select at the start.

我想你的,为什么它不工作,问题是真的,为什么的jsfiddle不能使它发挥作用的问题,即使我讨厌回答与那没关系的问题,我想你现在应该专注于解决你的问题,而不是的jsfiddle的问题,只需使用其他服务(如plunker)的;)

I think your question as to why it doesn't work is really a question of why jsfiddle can't make it work, and even though i'd hate to answer a question with "That doesn't matter", i think you should focus on solving your problems and not jsfiddle's problem and just use another service (like plunker) for now ;)

编辑:如果我猜(通常不是一个好主意SO)我想说的jsfiddle莫名其妙地打乱了模板或者添加注释节点模板,打破了一的RootNode要求对角模板。

If i were to guess (generally not a good idea for SO) i'd say jsfiddle somehow messes up the template adding perhaps a comment node to the template, breaking the "one rootnode" requirement for an angular template.

这篇关于本地项目的jsfiddle,但在Plunker做工精细的角度编译模板错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆