美文网首页
ng-repeat 使用方法

ng-repeat 使用方法

作者: 咏竹莉 | 来源:发表于2018-04-03 18:14 被阅读0次

js:

angular.module('myApp', []).controller('indexController', function ($scope, $http, $timeout) {
$scope.records = [
"菜鸟教程1",
"菜鸟教程2",
"菜鸟教程3",
"菜鸟教程4",
]

});

html:

<h1 ng-repeat="x in records">{{x}}</h1>

循环出来的结果:

菜鸟教程1
菜鸟教程2
菜鸟教程3
菜鸟教程4


ng-repeat 带索引:

<li ng-repeat="obj in nameList track by $index" ng-click="pageToElecAnalysis(obj.id,$index)">{{obj.leaserName}}</li>

注意: $index 是当前索引

相关文章