为什么在AngularJS模板中添加ng-repeat会破坏它? [英] Why does adding an ng-repeat to my AngularJS template break it?

查看:119
本文介绍了为什么在AngularJS模板中添加ng-repeat会破坏它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个AngularJS指令,其模板文件如下所示:

I have an AngularJS directive whose template file looks like this:

path/to/myDirectiveA.template.html :

<tr>
    <td bgcolor='#7cfc00'>Statement</td>
    <td bgcolor='#ff1493'>{{MyDirectiveACtrl.a.b}}</td>
</tr>

有效.输出看起来像这样:

It works. The output looks like this:

但是随后我通过添加ng-repeat来更改模板文件:

But then I change the template file by adding an ng-repeat like this:

<tr ng-repeat="currRow in [0, 1, 2, 3]">
    <td bgcolor='#7cfc00'>Statement</td>
    <td bgcolor='#ff1493'>{{MyDirectiveACtrl.a.b}}</td>
    <td bgcolor='#7cfc00'>{{currRow}}</td>
</tr>

这会导致它断裂,如下图所示.短语Hello World!不再显示!为什么?我该如何解决这个问题?

And that causes it to break as you can see in the image below. The phrase Hello World! is no longer showing up! Why? How can I fix this problem??

我根本看不出添加ng-repeat会导致此损坏的任何逻辑原因.对我来说根本没有意义.

I simply don't see any logical reason why adding an ng-repeat should cause this breakage. It doesn't make sense to me at all.

如果需要它,可以在

If you need it, here is the controller and directive that invoke it can be found in this question I posted earlier.

推荐答案

这可以解决问题($ parent)

may this solve the problem ($parent)

<tr ng-repeat="currRow in [0, 1, 2, 3]">
    <td bgcolor='#7cfc00'>Statement</td>
    <td bgcolor='#ff1493'>{{$parent.a.b}}</td>
    <td bgcolor='#7cfc00'>{{currRow}}</td>
</tr>

这篇关于为什么在AngularJS模板中添加ng-repeat会破坏它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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