Angular study notes (3) Ng-repeat traverse JSON and give style

Source: Internet
Author: User

View:

<div ng-app= "MyApp" ng-controller= "Myctrl" ><ul>
<li ng-repeat= "(k,v) in data" style= "{{$even? ' Color:red ': '} ' > <!--add style to an even line--{{ k}} Name: {{v.name}} URL: {{v.url}} </li>
<li ng-repeat= "(k,v) in Data" >
<span ng-if= "$first" style= "{{$first? ' Color:red ': '} ' >
{{V.name}} {{V.url}}
</span>< add red to the first element!--
<span ng-if= "$middle" style= "{{$middle? ' Color:blue ': '} ' ></span><!--middle element added blue---
{{V.name}} {{V.url}}
<span ng-if= "$last" style= "{{$last? ' Color:black ': '} ' ></span><!--last element added black--
{{V.name}} {{V.url}}

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

  

Controller:

var app = Angular.module (' myApp ', []);    App.controller (' Myctrl ', function ($scope) {     $scope. data = [            {name: ' Chengdu people ', url: ' chengduren.com '},            {name: ' Chengdu net ', url: ' chengduwang.com '},            {name: ' Chengdu Cloud ', url: ' chengduyun.com '},            {name: ' hdphp ', url: ' hdphp.com '},            { Name: ' hdcms ', url: ' hdcms.com '},        ];    });

  

Angular study notes (3) Ng-repeat traverse JSON and give style

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.