gpt4 book ai didi

angularjs 如何从我的项目模板中访问 ng-repeat 数组

转载 作者:行者123 更新时间:2023-12-01 12:48:45 24 4
gpt4 key购买 nike

我想做这个...

<span ng-repeat="item in array1" ng-include="'genericItemTemplate.html'">

还有这个……

<span ng-repeat="item in array2" ng-include="'genericItemTemplate.html'">

然后在 genericItemTemplate.. 中执行此操作...

[{{$index + 1}} of {{someArrayreference.length}}]

我可以在模板中引用 ng-repeat 的数组吗?

另请参阅我的长篇博文... https://groups.google.com/forum/?fromgroups=#!topic/angular/y_KuX0HRQ_U

还有我的笨蛋

http://plnkr.co/edit/dY7M76kPyLeK0fvVZhvB

迈克尔

最佳答案

使用 onload,一个 ng-include 可选参数:

<li ng-repeat="person in personlist=friends" ng-include="'myGenericTemplate.html'"
onload="len=friends.length"></li>

<li ng-repeat="person in personlist=collegues" ng-include="'myGenericTemplate.html'"
onload="len=collegues.length"></li>

[{{$index + 1}} of {{len}}] {{person.name}}

输出:

I have friends. They are:
[1 of 2] John a boy who is 25 years old.
[2 of 2] Mary a girl

I also have collegues. They are:
[1 of 3] Hoolio a boy who is 42 years old.
[2 of 3] Kitty a girl
[3 of 3] Marge a girl

关于angularjs 如何从我的项目模板中访问 ng-repeat 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13896843/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com