angularjs ng-repeat指令
对于遍历一个数组或对象已经不陌生了,而在angularjs中也是有遍历的方法,即ng-repeat指令。
一、遍历数组
直接给例子:
a:
<ul><li ng-repeat =' number in [1,2,3]'>{{number}}</li><ul>
这样输出的结果就是依次输出1,2 ,3
b:
<!DOCTYPE html> <html lang="en" ng-app = "myapp" > <head></head> <body> <div ng-controller = "mycontroller"> <button ng-repeat = "person in persons"> {{person.name}} {{person.age}} {{ $index}} </button> </div> </body>
对应的controller
angular.module('myApp',[]) .controller(‘mycontroller’, function($scope) { $scope.persons= [{name:'张三',age:'22'},{name:李四,age:34},{name:'王五',age:'20'}]; })
会依次在页面上显示三个button,上面依次为0 张三 22 ,1 李四 34 ,2 王五 20
$index为数组的索引
相关推荐
鸟菜小端前 2018-09-12
CrazyDogWang 2017-02-14
zbwroom 2016-09-23
princejingyun 2013-01-30
Oranq 2013-09-24
闲听风月 2018-01-16
forthemyth 2017-09-18
codergirl 2017-07-06
Inuyasha 2017-01-21
forthemyth 2017-01-21
鸟菜小端前 2017-01-19
thesameguo 2016-12-31
itseebin 2019-04-29
DataCastle 2016-12-13
鸟菜小端前 2016-11-02
codergirl 2019-04-29
鸟菜小端前 2019-04-26
Inuyasha 2016-08-23
雅特岚蒂斯 2019-04-25