its*_*sme 2 javascript arrays view angularjs ng-class
嗨,我正在尝试通过一个元素添加一个类ng-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();
});
});
Run Code Online (Sandbox Code Playgroud)
然后在视图中,我做:
<div ng-view ng-animate class="" ng-class="{'slide': config.app_routes.indexOf(config.app_url) == -1}"></div>
Run Code Online (Sandbox Code Playgroud)
但似乎它永远不会起作用,因为它永远不会增加课程slide.同时console.log效果很好,只有在正确时才返回-1:O
将您的逻辑移动到范围变量中:
<div ng-view ng-animate ng-class="{ 'slide': someVar }"></div>
并设置$scope.someVar = true每当config.app_routes.indexOf(config.app_url) == -1.如何执行此操作取决于config.app_routes更新的方式和时间.