Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear $scope on logout in Angular js

In my controller I am storing data as $scope.$parent.dossierSummaries = data; but after log out and login the application $scope.$parent.dossierSummaries retains the same old data.

I am doing this on log out

.success( function( response, status ) {
    if ( response.status > 0 ) {
        var u = $rootScope.user.username;
        $cookieStore.remove('myapp');
        $rootScope.user = { username: '', role: 0 };
        success(u);
    }
    else {
        error(response.messages);
    }
})
.error( function( response, status ) {
    error(['There was an error logging you out.']);
});
like image 587
Prashobh Avatar asked Dec 25 '22 21:12

Prashobh


1 Answers

in angularJS, you shouldn't set the variable directly to a controller but you should retrieve it from a service instead. So whenever you load a controller you should write a init() function to get value of that model. So everytime you will have the correct data from server.

Code example and docs : http://docs.angularjs.org/guide/dev_guide.services.creating_services

like image 69
Dzung Nguyen Avatar answered Dec 28 '22 13:12

Dzung Nguyen