Accessing the nested Arrays using ng-repeat in angularjs

倾然丶 夕夏残阳落幕 提交于 2019-12-18 16:49:10

问题


JSFiddle

I'm not able to access the array images in the nested collection. Why am I not able to see any output?

The model:

var obj = [{
    "id": "7",
    "date": "1 Jan",
    "images": ["507f42c682882", "507e24b47ffdb", "507e2aeca02d5", "507e2b19663a9"]
}, {
    "id": "7",
    "date": "1 Jan",
    "images": ["507f42c682882", "507e24b47ffdb", "507e2aeca02d5", "507e2b19663a9"]
}];

This is the HTMl with ng-repeat:

<ul>
    <li ng-repeat="img in item"> 
        <br /> 
        <li ng-repeat="img1 in img.images">{{img1}}</li>
    </li>
</ul>

Can anyone point me to what I'm missing?


回答1:


The problem is you are trying to repeat a list of li elements inside of a li element, which is invalid HTML. As such, angular will not render this.

Update your HTML to:

<ul>
    <li ng-repeat="img in item"> 
        <ul>
            <li ng-repeat="img1 in img.images">{{img1}}</li>
        </ul>
    </li>
</ul>


来源:https://stackoverflow.com/questions/21161922/accessing-the-nested-arrays-using-ng-repeat-in-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!