我有一个使用 AngularJs 构建的应用程序。
Html 文件包含这样的信息:
<div>
<h3 ng-if="..."></h3>
<h3 ng-if="..."></h3>
<h3 ng-if="..."></h3>
<h3 ng-if="..."></h3>
</div>
所以在网站上我可以有 4 个不同的元素。如果我只有两个,那么我想使用不同的类,然后使用其中的 4 个。
if(myVar == 0){
$scope.life_class='';
}else if(myVar ==1){
$scope.life_class='doscol';
}else if(myVar ==2){
$scope.life_class='tricol';
}else if(myVar ==3){
$scope.life_class='foucol';
}else{
$scope.life_class='fifcol';
}
对于“foucol”和“fifcol”类,我想添加另一个类,但前提是“foucol”和“fifcol”正在使用中。
我尝试了很多次类似的不同解决方案:
if(active_date_count >= 2) {
document.getElementById("h3").foucol += " font_class";
document.getElementById("h3").tricol += " font_class";
}
但它不能正常工作。有任何想法吗?提前致谢
最佳答案
在 Angular 中,你可以使用 ng-class
实现条件类。
<h3 ng-class="{'font_class': condition}" ...></h3>
有关详细信息,请参阅 https://docs.angularjs.org/api/ng/directive/ngClass
关于css - AngularJS:如何在某些情况下添加两个不同的类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36183976/