AngularJS

Ternary operator ng-class expression vs controller method. Alex Paluzzi

HTML

<div ng-controller="MyCtrl">
   
    
    <div ng-class="isIndented =='All' ? 'indent' : 'no-indent', isIndented1 =='' ? 'indent' : ''" >
        I'm ng-class from inline ternary.
    </div>
    
    <button ng-click="isIndented = !isIndented">Toggle Class</button>
</div>

CSS

.indent {
    color: green;
    margin-left:10px;
    padding-left:10px;
}
.no-indent {
    color: red;
}
.indent1 {
    border-color: 1px solid blue;
    margin-left:10px;
    padding-left:10px;
}

JavaScript

var myApp = angular.module('myApp',[]);


function MyCtrl($scope) {
    
    $scope.isIndented = 'All';
    $scope.isIndented1 = '';
    


}