84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
在angularjs2中,*ngFor是实现循环的指令,实践的时候,发现无法嵌套多层的循环。如果要实现嵌套2个以上的循环,应该怎么实现呢
走同样的路,发现不同的人生
You can implement nested loops with multiple ngFors. It mainly depends on how your data format corresponds.
Data format:
// demo.json { "nav": [{ "title": "一级导航1", "subs": [ { "txt": "二级导航1", "link": "#" }, { "txt": "二级导航2", "link": "#" }, ] }, { "title": "一级导航2", "subs": [ { "txt": "二级导航2", "link": "#" }, ] }, { "title": "一级导航3", "subs": [ { "txt": "二级导航3", "link": "#1" }, ] }] }
Code example:
// 导航带子菜单循环例子 <ul> <li *ngFor="let nav of navs"> // 这里是外层循环 <strong>{{nav.title}}</strong> <a *ngFor="let sub of nav.subs" href="{{sub.link}}"> // 这里是内层循环 {{sub.txt}} </a> </li> </ul>
You can implement nested loops with multiple ngFors. It mainly depends on how your data format corresponds.
Data format:
Code example: