angular ng-repeat数组中的数组实例

编程学习 2021-07-04 19:20www.dzhlxh.cn编程入门
狼蚁网站SEO优化长沙网络推广就为大家带来一篇angular ng-repeat数组中的数组实例。长沙网络推广觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随长沙网络推广过来看看吧

//先定义一个数组

anular代码:

var app = angular.module('serApp', []); 

app.controller('indexCtrl', function($scope, $http) 
{ $scope.arrs = [{

<BR>                   n:'a'; 
        arr:['1','2','1'] 
      },{<BR><BR>                    n:'b'; 
        arr:['4','5','6'] 
      }]; 
    }) 

html 代码:

<BR>    
<div ng-controller="indexCtrl"><BR>      
<p>{{name}}</p><BR>      

<ul><BR>        
 <li ng-repeat="name in names">{{name.n}}<BR>          
 <p ng-repeat="a in name.arr track by $index" id="{{$index}}">{{a}}</p><BR>        
 </li><BR>      
</ul>
<BR>    
</div><BR><BR> 

track by $index  在有重复值时需加上这段代码 不然浏览器会报这个错 Error: [ngRepeat:dupes]并且不会渲染到页面

以上这篇angular ng-repeat数组中的数组实例就是长沙网络推广分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持狼蚁SEO。

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板