Hi,

I'm trying to make an angular app by bootstrapping it with main module like 
this:

angular.element(document).ready(function() {
  angular.bootstrap(document, [
    mainModule.name
  ], {
    strictDi: true
  });
});


so I don't have ng-app or any ng-controller in "root" view (index.html).

I have made an myLogin directive which receive url attribute for 
authentification backend API, and global user object, like this:

<body>
  <my-login url="api.myserver.com/authentification" 
user={{user}}></my-login>
  <div ui-view></div>
...


but (for example) in footer should be an "login" state box to show user 
profile pic:

...
<img ng-src='api.myserver.com/profiles/user-{{user.id}}.png' />
</body>

What is the best approach to take this "global" user object created? I have 
googled last few hours and most of results refer me to make angular service 
or provider, but in both case I need to define some global ng-controller 
with injected dependency to this service.
The best approach I have found is to set $rootScope variable but I'm new in 
angular and I'm not sure is it regular solution.

angular.module('myApp', []).run(['$rootScope', function($rootScope) {
  var user = { id: 16854161}
    $rootScope.user = user;
}]);

in this case I can do this:
<body>
  <img ng-src='api.myserver.com/profiles/user-{{$root.user.id}}.png' />
</body>

Is there any better solution?
Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to