Search code examples
angularjscontrollerangularjs-scopeng-class

ng-class not working with $scope variavles defined in the controller


I can't make my ng-class work using $scope varibales defined in the controller
I tried this:

HTML

<nav  id="main-navbar" class="navbar navbar-default navbar-fixed-top"
            ng-class="{'on': some}">

JS

$scope.some = true;

When I change it to like this the class is applied

ng-class="{'on': true}"

Am im missing something?


Solution

  • This might be related to the fact that you bound a primitive to the scope. Can you try with:

    HTML

    ng-class="{'on': obj.some}">
    

    JS

    $scope.obj = {
        some: true
    }