【发布时间】:2018-05-14 02:52:31
【问题描述】:
我对 AngularJs 中的 ng-repeat 有疑问。我有一个具有 3 个不同键的对象数组,其中一个键是对象数组。所以我只是将ng-repeat 用于主数组,如下所示:
<div class="post-content" ng-repeat="post in nfc.posts track by $index">
...
</div>
一切正常。但是当我在这个循环中使用嵌套的ng-repeat 时,我什么也得不到。我在嵌套ng-repeats 之前使用了很多并且没有遇到任何问题。代码如下:
comments:: {{post.comments}}
<div class="post-comment" ng-repeat="comment in post.comments">
comment: {{comment}}
<img src="{{comment[3]}}" alt="" class="profile-photo-sm" />
<p>
<a href="" class="profile-link">{{comment[4] + ' ' + comment[5]}}</a> {{comment[6]}}
</p>
</div>
comments:: {{post.comments}} 语句向我显示了内容,但ng-repeat 似乎无法正常工作。
浏览器控制台中的comments 对象示例在这里
Array(3)
0: {
0: 10196,
1: 10325,
2: 62,
3: 0,
4: Sun Feb 18 2018 21: 56: 58 GMT + 0330(+0330),
5: "text",
6: "text",
7: "text",
8: "text",
9: "text",
$$hashKey: "object:96"
}
1: {
0: 10195,
1: 10325,
2: 50,
3: 0,
4: Sun Feb 18 2018 20: 15: 41 GMT + 0330(+0330),
5: "text",
6: "text",
7: "text",
8: "text",
9: "text",
$$hashKey: "object:97"
}
2: {
0: 10194,
1: 10325,
2: 62,
3: 0,
4: Sat Feb 17 2018 12: 36: 39 GMT + 0330(+0330),
5: "text",
6: "text",
7: "text",
8: "text",
9: "text",
$$hashKey: "object:98"
}
这个数组是数组数组,我从API收到它后将它转换为对象数组。
我的错误在哪里?
【问题讨论】:
-
您的控制器中没有 totoObject(array) 函数,即使您没有从任何地方导入它。是不是搞错了?
-
是的,这是一个打字错误@ImranAhmadGhazali
-
你得到这个错误了吗?
-
很遗憾没有!@ShashankVivek
-
感谢您的提问。我向页面添加了一些加载,并且此代码没有任何更改!我认为这与 angularJs 中的生命周期和摘要有关。但我仍然不知道原因。 @ShashankVivek
标签: angularjs angularjs-ng-repeat