详解AngularJS ng-class样式切换

整理文档,搜刮出一个详解AngularJS ng-class样式切换,稍微整理精简一下做下分享

1、HTML

rush:xhtml;">
irst]" ng-click="isFirst = !isFirst">First


irst]" ng-click="toggleFirst()">First

2、controller

rush:js;"> appControllers.controller('TestlCtrl',function ($scope,$state) { $scope.isFirst = false; $scope.isSecond = false; $scope.isThird = false;

$scope.hasAll = false;
$scope.hasFirst = false;
$scope.hasSecond = false;
$scope.hasThird = false;

$scope.toggleAll = function () {
$scope.hasAll = !$scope.hasAll;
console.log($scope.hasAll);
var dynamicValue = $scope.hasAll;
$scope.hasFirst = dynamicValue;
$scope.hasSecond = dynamicValue;
$scope.hasThird = dynamicValue;
}

$scope.toggleFirst = function () {
$scope.hasFirst = !$scope.hasFirst;
checkAll();
}

$scope.toggleSecond = function () {
$scope.hasSecond = !$scope.hasSecond;
checkAll();
}

$scope.toggleThird = function () {
$scope.hasThird = !$scope.hasThird;
checkAll();
}

function checkAll() {
if ($scope.hasFirst == true && $scope.hasSecond == true && $scope.hasThird == true) {
console.log("123ok");
$scope.hasAll = true;
} else {
console.log("123no");
$scope.hasAll = false;
}

}
})

3、效果

4、循环列表,判断索引添加样式

rush:xhtml;">

*、

rush:xhtml;"> <ion-item class="item-divider"> vendorId==0]"> vendorId==0">合作{{item.vendorName}}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...