I have the angular rail code But here's the problem, when I run it in my Controllers, it always shows undefined. Unless I do not put it in the function block, so my guess is that the controller is run before the value of Any suggestions I'm able to use async from .s (.in)? If I call the following code in every controller, it seems that I keep repeating myself. UPDATE is here where the Dean event from firebaselog I think that will re-mention me again. The callback is async. The injector is loading all the modules for your app. So your assumption about your controller starts for the first time. What you're doing effectively with the $ timeout (function () {...}, 0), forcing the code to run the next code is not the digest loop but me It seems that this is what you are trying to accomplish. I am not sure where 'firebase log' is being broadcasted; But you may find that this complete implementation will be more straightforward as an angular service. then in your controller ...... This enables you to access these variables wherever you are injecting FireBaseService service. .run () , so when the app is initialized, So i set the root under 2 wars. Because I decide to use these wires in every way (pages) and controllers. async
app.run (function ($ Rootscope, $ timeout, firebase) {$ Rootscope. $ ('FirebaseLoggedIn', function (event, authUser) {$ Timeout (function () {$ rootScope._isLoggedIn = true; $ rootScope._authUser = authUser;}, 0);});
.run () vars ;
App.controller ('foo', function ($ scope) {console.log ($ scope._authUser); // always unspecified // unless I do the following ///scope.clickme = function () {Console.log} ($ Scope._authUser)};});
$ rootScope. $ ('FirebaseloggedIn', function (event, authUser } {});
App Service ('firebase', ['$ rootscope', function ($ Rootscope)) {// Defined Firebase DB URL this.firebaseRef = new Firebase ("https: //test.firebaseio.com"); This.onLoginStateChanges = new FirebaseAuthClient (this.firebaseRef, function (error, user) {if (user) {$ rootScope. $ Emit ("firebaseLoggedIn", user); // certified user} else if (error) {$ rootScope. $ Emit ("firebaseloginError", error); // authentication failed} and {$ Rootscope. $ Emit ("firebaseLogout"); // user login}}}}});
app ('FireBaseService', function ($ Rootscope)) has been recovered through the methods given below. Var isLoggedIn = false; Var authUser = {}; // This is the only place that you handle logged in events, set user references. $ RootScope $ ('FirebaseLoggedIn', function (event, authUser) {IsLoggedIn = true; authUser = authUser;}); Return some functions to expose the above variables {getIsLoggedIn: function () {return isLoggedIn;}, getAuthUser: function () {return authUser;}}});
app.controller ('foo', function ($ radius, $ log, firebase service) { If (FireBaseService.getIsLoggedIn ()) {$ log.info (FireBaseService.getAuthUser (.name);}}};
No comments:
Post a Comment