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 ~