0

I have two controllers:

Parent Controller

'use strict';

app.controller('CoreController', function($scope,$window,$location,$rootScope,AuthFactory) {
    var requiredLogin = true;

    $rootScope.bodyClass = '';
    $rootScope.pageTitle = '';

    $scope.Usuario = AuthFactory.user();
});

Child Controller

'use strict';

app.controller('SignController', function($scope, $controller, $stateParams,$rootScope, AuthFactory) {
    angular.extend(this, $controller('CoreController', {$scope: $scope}));

    $scope.EmailDefault = $stateParams.email;

    if(angular.isDefined($stateParams.pass)){
        $scope.SpecifyPass = $stateParams.pass;
    }else{
        $scope.SpecifyPass = true;
    }

    switch($stateParams.mode) {
        case "github":
            $rootScope.bodyClass = "dgdfg";
        break;
        case "google":
            $rootScope.bodyClass = "login_registro";
        break;
        default:
            $rootScope.bodyClass = "login_registro";
    }
});

I set class like this:

<body id="inicio" ng-class="bodyClass" data-spy="scroll" data-target=".navbar-fixed-top" data-offset="200">

But when i try to modify $rootscope the class doesnt change.

What do i do wrong?

50l3r
  • 1,549
  • 4
  • 16
  • 27

2 Answers2

0

Try this,

<body id="inicio" ng-class="$root.bodyClass" data-spy="scroll" data-target=".navbar-fixed-top" data-offset="200">

it might be a good idea thoughto not actually use rootscope at all.

z.a.
  • 2,549
  • 3
  • 12
  • 16
0

I solved it adding "statechangedsucces" event to my switch statement in Child controller:

'use strict';

app.controller('SignController', function($scope, $controller, $stateParams,$rootScope, AuthFactory) {
    angular.extend(this, $controller('CoreController', {$scope: $scope}));

    $scope.EmailDefault = $stateParams.email;

    if(angular.isDefined($stateParams.pass)){
        $scope.SpecifyPass = $stateParams.pass;
    }else{
        $scope.SpecifyPass = true;
    }

    $scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){
        switch($stateParams.mode) {
            case "github":
                $rootScope.bodyClass = "login_github";
            break;
            case "google":
                $rootScope.bodyClass = "login_google";
            break;
            default:
                $rootScope.bodyClass = "login_registro";
        }
    });
});
50l3r
  • 1,549
  • 4
  • 16
  • 27