Saturday, 3 May 2014

Angular js Cookies

Here I am going to explain about how to store login credentials into angular cookies.

function( $rootScope, $http, $cookieStore)

$rootScope.user = { username: model.username, role: role};

//Set Cookie
$cookieStore.put( 'yourmodule', $rootScope.user );


$rootScope is global and you can use anywhere in your module

For getting user name in any controller in the same module

var username = $rootScope.user.username ;

var role = $rootScope.user.role ;

Destroy cookie

For destroying cookies on log out add this simple code on your log out functionality.


$rootScope.user = { username: '', role: 0 };

Related Posts

1. Save highchart as binary image

2. Communicate with controllers in angular js

3. Angular routing

4. Rating Stars using angular js Directive concept

5. Loop concept in angular js

6. Filtering concept in angular js

No comments :

Post a Comment