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

查看:24
本文介绍了为什么向我的 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天全站免登陆