我使用angularjs有以下代码,我的目标是显示位于img / gallery /中的图像,图像名称从1到40被麻木,希望在循环中调用它们。我认为这段代码可以工作,但它只出于某种原因显示第一张图片。
<div id="links" ng-init="inc = [
{ name: 1,name: 2,name: 3,name: 4,name: 5,name: 6,name: 7,name: 8,
name: 9,name: 10,name: 11,name: 12,name: 13,name: 14,name: 15,name: 16,
name: 17, name: 18,name: 19,name: 20,name: 21,name: 22,name: 23,name: 24,
name: 25,name: 26, name: 27,name: 28,name: 29,name: 30,name: 31,name: 32,
name: 33,name: 34,name: 35, name: 36,name: 37,name: 38,name: 39,name: 40}]">
<div ng-repeat="i in inc">
<a ng-href="img/gallery/{i.name}.jpg" title="AnsarDay" data-gallery>
<img ng-src="img/gallery/{{i.name}}.jpg" alt="ansarday"
height="100" width="100">
</a>
</div>
</div>
答案 0 :(得分:0)
使用&#39; ng-repeat =&#34; i在[1,2,3,....,n]&#34;代替。
<div id="links">
<a ng-repeat="i in [1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20,21,22,23,24,
25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40]"
href="img/gallery/{{i}}.jpg" title="AnsarDay" data-gallery>
<img ng-src="img/gallery/{{i}}.jpg" alt="ansarday" height="150" width="150">
</a>
</div>