Search code examples
javascriptangularjsng-class

ng-class - Error: Token '-' is at column {2}


I have a problem with ng-class. If the role has admin privileges, it is to add a class-disabled state. Now occurs error

html:

<label class="toggle modal-label-box" ng-class="{state-disabled: checkCanModify()}">
   <input type="radio" name="radio-toggle" ng-model="role" value="guest">
   <i data-swchon-text="ON" data-swchoff-text="OFF"></i>No role
</label>

js:

$scope.checkCanModify = function() {
    return ($scope.role == "admin" ? true : false);
};

error:

Syntax Error: Token '-' is at column {2} of the expression [{3}] starting at [{4}].

How i can this fixed ? Regards


Solution

  • Put quotes around the class:

    "{'state-disabled': checkCanModify()}"