3

我想做这个...

<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

迈克尔

4

1 回答 1

4

使用 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
于 2012-12-15T23:27:48.467 回答