Talking about the use method of Ng-class in Angularjs _angularjs

Source: Internet
Author: User

There are three different ways:

1. Binding via $scope (not recommended)
2, through the object array binding
3. Binding by Key/value key value

Implementation method:

1. Binding via $scope (not recommended):

Function Ctrl ($scope) {  
  $scope. ClassName = "selected"; 
 
 

2, through the object array binding:

Function Ctrl ($scope) {  
  $scope. isselected = true; 
 
 

Increases the selected style when IsSelected is true, and increases the unselected style when isselected is false.

3, through the Key/value key value to bind:

Function Ctrl ($scope) {  
  $scope. IsA = true; 
  $scope. IsB = false; 
  $scope. IsC = false; 
 
 

Adds a style when Isa is true, increases the B style when ISB is true, and increases the C style when ISC is true.

<ion-list> 
  <ion-item ng-repeat= "project in Projects" ng-click= "Selectproject (Project, $index)" Ng-class = ' {Active:activeproject = = project} ' > 
    {project.title}} 
  </ion-item> 

Creates ion-item based on the projects Loop, adding an active style when ActiveProject is the current loop to project.

A few notes:

1, do not recommend the first method, because controller $scope should only data and behavior

2, Ng-class is to increase the relevant style, and class can be used simultaneously

The above is a small series for everyone to talk about the use of Ng-class Angularjs in all the content, I hope that we support cloud-Habitat Community ~

Related Article

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.