Syed Syed -4 years ago 59
AngularJS Question

Angularjs rootscope not updating ngClass when route change

On

$routeChangeStart
I like to apply
of-h
class and on
$routeChangeSuccess
either I like remove
of-h
class or change it to
of-v
class. Now only
of-h
class get applied.

HTML

<div class="container-outer" ng-class="addClassOnRouteChange">
<div class="container" ng-view autoscroll="true" ng-class="fadeNgView">
<!-- Views will be rendered here -->
</div>
</div>


JS

angular.module('starter', ['ngRoute', 'ngAnimate', 'myApp.controllers'])

.run(['$window', '$location','$rootScope', function ($window, $location, $rootScope) {
$rootScope.fadeNgView = '';

$rootScope.$on('$routeChangeStart', function() {
//event button item list to move forward
$rootScope.next = function() {
console.log('start');
$rootScope.fadeNgView = 'fade-ng-view';
$rootScope.addClassOnRouteChange = 'of-h';
}
});

$rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
$rootScope.addClassOnRouteChange = 'of-v';
});
}]);

Answer Source

Try This :

$rootScope.$apply(function(){
    $rootScope.addClassOnRouteChang‌​‌​e = 'of-h';
});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download