Issue
On my main page where angular will be bootstrapped (initially loaded), I will already have an object that my application generates that has user information (isLoggedIn, username, etc.).
I don't see a point of loading angular, and then making an extra API call to get this information.
How can I pass this to angular?
Solution
angular.module('myApp').value('myVariable', myVariable)
This will load the object into an injectable static object. Note that you need to call this after you're sure that the object exists and has the correct values.
Also, typically objects that are injected into the window object artificially will already be available for angular (however, this is bad practice).
So if your variable is set like this:
// without var!
myObj = { isLoggedIn: true, username: 'myUser' }
or:
window.myObj = { isLoggedIn: true, username: 'myUser' }
It should be available from window. The injection method is preferred, mind you.
Answered By - casraf
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.