mercredi 1 juin 2016

Change ng-if statement in app.js from controller

I want to change my ng-if value "loggedIn" in index.html from my login/login.js by using this codes

$scope.doLogin = function() {
    console.log('Logging in as ', $scope.loginData.email);
  AuthService.login($scope.loginData)
    .then(function() {
        $rootScope.loggedIn = true;
        $scope.layout = 'styles';
        $state.go('app.mainReg');

        $stateParams.id = $currentUserId;
        console.log($currentUserId);
    });
};

and I have this kind of stateProvider in my app.js

.state('app', {
            url:'/',
            abstract: true,
            views:{
                'bodyLogin': {
                    templateUrl : 'views/login/body.html',
                    controller  : 'BodyController'
                },
                'bodyMain': {
                    templateUrl : 'views/main/body.html',
                    controller  : 'BodyController'
                }
            }
        })
.state('app.mainUnreg', {
            url:'home',
            views: {
                'content@app': {
                    templateUrl : 'views/login/home.html',
                    controller  : ''
                }
            }
        })
.state('app.mainReg', {
            url:':userID',
            views: {
                'header@app': {
                    templateUrl : 'views/main/header.html',
                    controller  : ''
                },
                'sidebar@app': {
                    templateUrl : 'views/main/sidebar.html',
                    controller  : ''
                },
                'middle@app': {
                    templateUrl : 'views/main/home.html',
                    controller  : ''
                },
                'footer@app': {
                    templateUrl : 'views/main/footer.html',
                    controller  : ''
                }
            },
            controller: 'MainController'
        })

and I separate each state by div

<div ng-if="!loggedIn" ui-view="bodyLogin" class="site-wrapper" ui-sref-active="app.mainUnreg"></div>

<div ng-if="loggedIn" ui-view="bodyMain" ui-sref-active="app.mainReg"></div>

but, I seems that it didn't give any effect, even I have logged in and being redirected, the statement for loggedIn didn't change, still false

I have put the files in GitHub

Does anyone have any idea where I made some mistake, so my loggedIn statement couldn't be changed?

Aucun commentaire:

Enregistrer un commentaire