Amy
Amy

Reputation: 163

How to add condition class in angularjs

if (url.indexOf('master/confirm-account') > 0) {
    $scope.accountInfo = 'Confirm Account';
    $scope.page = 'confirm_account';
    $scope.activeTab = true;
} else if (url.indexOf('master/master-profile') > 0) {
    $scope.accountInfo = 'Confirm Account';
    $scope.page = 'master_profile';
    $scope.activeTab = true;
} else {
    $scope.accountInfo = 'Create Account';
}


<div ng-class = "{'process-step' : true, '({{page}}=='confirm_account') ? 'active-tab' : ' '}" >

How can I add process-step and active-tab class Expected result if condition match then it become like that

Upvotes: 1

Views: 55

Answers (2)

Jins Peter
Jins Peter

Reputation: 2469

Seeing to the complexity of your class matching logic you could go for second way of implementing ng-class

** Inside HTML**

<div class="process-step" ng-class="ctrl.getPageBasedClass()">

Inside Controller

var self.getPageBasedClass = function(){

   var yourClassNameAsString = // your logic for class name 
   return yourClassNameAsString;
}

Upvotes: 0

invader7
invader7

Reputation: 492

The ng-class works like

{'add_this_class' : (if_this_expression_is_true)}

and not in the other way.

try this

<div class="process-step" ng-class="{'active-tab' : (page =='confirm_account') }">

Upvotes: 1

Related Questions