admin管理员组文章数量:1332345
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
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
- As I know, indexOf is not supported in some browsers. If that's the case, you need a polyfill – Khanh TO Commented Feb 1, 2014 at 9:21
- @KhanhTO it won't work only where it is supported man :d on Chrome it doesn't works – Filippo oretti Commented Feb 1, 2014 at 9:21
1 Answer
Reset to default 8Move 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.
本文标签: javascriptAngular jsngclassquotquot with simple condition won39t workStack Overflow
版权声明:本文标题:javascript - Angular js - ng-class="" with simple condition won't work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742325195a2453569.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论