0

I am working on web application. once user log in i need to load user profile data somewhere which will be available to all controllers also to other application by adding dependency or something .

i was thinking of writing ng-init() method and then storing all values in factory but is there any other way to achieve this i would just like to confirm.

Please suggest what can i use to store user basic profile data ? is there any way to store in config or provider ?

drawerApp.config([ '$interpolateProvider',
    function ($interpolateProvider) {

 }]);
anam
  • 3,905
  • 16
  • 45
  • 85

2 Answers2

2

I think its better to store it in localStorage of the browser as a Object

to set

 var setUserData = {name:"abc",age:25}
 localStorageService.set('userData',JSON.stringify(setUserData));

to get $scope.userData = JSON.parse(localStorageService.get('userData'));

Kalhan.Toress
  • 21,683
  • 8
  • 68
  • 92
  • I agree. Remember localStorage capacity is usually 5MB at most (http://stackoverflow.com/questions/2989284/what-is-the-max-size-of-localstorage-values), but it should generally suffice for user profile data... – MarcoS Dec 10 '14 at 10:13
  • @KalhanoToressPamuditha then on logout i will have to remove all this data from localStorage? is it safe ? – anam Dec 10 '14 at 10:17
  • if ur going to save sensitive data definitely not its not safe, storing sensitive data in javascript / scope variables are also not safe. u have to find another way of saving sensitive data. if ur need to destroy the data when logout `localStorage.clear()` will do the job. – Kalhan.Toress Dec 10 '14 at 10:33
0

You can use root scope.Root scope is shared among all controllers and all html templates.so just store your user profile data in root scope.

Ankit Gupta
  • 2,529
  • 2
  • 15
  • 26