Angular implementing navigation Ng-click switching

Source: Internet
Author: User

Angular write the navigation. Self-taught angular has been for some time.

<!doctype html>
<meta charset= "UTF-8" >
<title>Document</title>
<script src= '. /angular-1.3.9/angular.js ' ></script>
<style>
*{
List-style:none;
margin:0;
padding:0;
}
. listbox{
width:600px;
height:30px;
margin:0 Auto;
border:1px solid #ccc;
box-shadow:2px 2px 3px #333;
}
. ListBox li{
width:100px;
Float:left;
height:30px;
line-height:32px;
Text-align:center;
Cursor:pointer;
Font-weight:bold;
Color: #333;
font-family: ' Microsoft ya Black ';
border-radius:15px;
}
. ListBox li.cour{
Background:skyblue;
Color: #fff;
text-shadow:1px 1px 1px #333;
}
</style>
<body ng-app= ' app ' >
<ul ng-controller= ' cont ' class= ' listbox ' >
<li ng-repeat= ' I in List ' ng-click= ' cour ($index) ' ng-class= ' {true: ' Cour ', False: '} [I.isclick] ' >{{i.text}}< /li>
</ul>
<script>
var data=[{text: ' Home ', Isclick:false},{text: ' News '},{text: ' Project ', Isclick:false},{text: ' Cooperate ', Isclick: False},{text: ' About Us ', Isclick:false},{text: ' More ', isclick:false}];
var app=angular.module (' APP ', []);//define Angular module
App.controller (' cont ', function ($scope) {//angular Controller
$scope. list=data;//Injection Data
$scope. list[0].isclick=true;//First Add Style
$scope. Cour=function (index) {
Here with JS implementation, without JS with angular how to achieve
for (Var i=0;i< $scope. list.length;i++) {
$scope. list[i].isclick=false;//when clicked, no other style is added.
}

$scope. List[index].isclick=true;//ng-click when the current add style
}

})
</script>
</body>

Ng-click the time to let the unselected do not add style, with angular need to use what?

I am here directly with JS implementation, and I feel the data in the Isclick:false, with variables should also be possible!

Angular implementing navigation Ng-click switching

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.