Angular js - ng-class="" with simple condition won't work

angularjs, arrays, javascript, ng-class, view

Solution

Move your logic into a scope variable:

`<div ng-view ng-animate ng-class="{ 'slide': someVar }"></div>`

and set `$scope.someVar = true` whenever `config.app_routes.indexOf(config.app_url) == -1`. How you do this depends how and when `config.app_routes` is updated.

Problem

Hi, i'm trying to add a class to an element via `ng-class`. As you can see, the code is very simple but it doesn't add the class: ``` app.run(function($rootScope, $location,$http,ngDialog,array_helper){ var update = function() { /*CONFIG PARAMS*/ $rootScope.config = {}; $rootScope.config.app_routes = [ "/", "/channels", "/channels/create", "/users", "/auth/login", "/auth/signup" ]; console.log($rootScope.config.app_url); console.log($rootScope.config.app_routes.indexOf($rootScope.config.app_url)); }; $rootScope.$on('$routeChangeStart', function() { update(); }); }); ``` Then in the view, i do: ``` <div ng-view ng-animate class="" ng-class="{'slide': config.app_routes.indexOf(config.app_url) == -1}"></div> ``` But it seems it never works, as it never adds the class `slide`. Meanwhile `console.log` works great and returns -1 only when it is right :O

Original source