angular 学习笔记(3) ng-repeat遍历json并且给样式

视图:

 

<div ng-app="myapp" ng-controller="myctrl">
<ul>
<li ng-repeat="(k,v) in data" style="{{$even?'color: red':''}}"> <!--给偶素行添加样式--> {{k}} 名称:{{v.name}} 网址:{{v.url}} </li>
<li ng-repeat="(k,v) in data">
<span ng-if="$first" style="{{$first?'color:red':''}}">
{{v.name}} {{v.url}}
</span><!--第一个元素添加红色-->
<span ng-if="$middle" style="{{$middle?'color:blue':''}}"></span><!--中间元素添加蓝色-->
{{v.name}} {{v.url}}
<span ng-if="$last" style="{{$last?'color:black':''}}"></span><!--最后一个元素添加黑色-->
{{v.name}} {{v.url}}

</li> </ul> </div>

  

控制器:

var app = angular.module('myApp',[]);
    	app.controller('myCtrl',function($scope){
    		 $scope.data = [
            {name:'成都人',url:'chengduren.com'},
            {name:'成都网',url:'chengduwang.com'},
            {name:'成都云',url:'chengduyun.com'},
            {name:'hdphp',url:'hdphp.com'},
            {name:'hdcms',url:'hdcms.com'},
        ];
    	});

  

posted @ 2017-10-23 17:06  斯丢皮德曼  阅读(1591)  评论(0编辑  收藏  举报