angularjs - Angular passing data from factory to controller -
I am trying to store an authorized user id variable, which I can send to administrators. I know how I am trying to overcome the data from the conclusion of my factory object, but there is an issue about how I can fix it.
This is my factory:
myApp.factory ('authentication', function ($ firebase, $ firebaseAuth, FIREBASE_URL, $ location) {var ref = new Firebase ( FIREBASE_URL); var simpleLogin = $ firebaseAuth (ref); var authorized; var myObject = {login: function () {simple_login return $ auth home page} (function (authData) {authorized = authData.uid; console.log ( "Logged in as:", authData.uid);}) hold (function (error) {console.error ("authentication failed:", error);});}, auth: authorized} // MyObject myObject;}); Here's my controller:
myApp.controller ('Meetings Controller', Function ($ Range, $ Firebase, Authentication) {var ref = new Firebase ('http://i2b2icons.firebaseio.com/'); var meetings = $ firebase (ref); $ scope.authid = authentication.auth; $ scope.meetings = meetings. $ AsObject (); // $ scope Id = = Authentication.login.id; $ scope.addMeeting = function () {Meetings. $ Push ({name: $ scope.meetingname, date: Firebase.ServerValue.TIMESTAMP}). Then (function () {$ scope. Name of meeting = '';})}} // gathering $ scope.delete meeting = function (key) {takings. $ Extract (key);} // denilemetti C}); // Meeting Controller I'm actually trying to get the $ scope.authid variable to choose the value of authoring from the login function of myObject.
The login method should already be asked by logging in through this controller:
myApp.controller ('RegistrationController', function ( $ Scope, $ firebaseAuth, $ location, authentication) {$ scope.login = function () {Authentication.login ();} // login}); // Register Controller
You just do local variables Authorized Your factory has no relation to its Authentication.auth that you are trying to access your controller (unless you set a price for it when you create a factor and which way Is also not intended). Instead, return a predefined object back to your factory and return it to that object. Set the property on the object reference. Var simple login = $ firebaseAuth (referee)
myApp.factory ('authentication', function ($ firebase, $ firebaseAuth, FIREBASE_URL, $ location) {var ref = new Firebase (FIREBASE_URL) ; // Define for factory wafde = {login: login, authoritative: blank}; function login () {return simple ligin. $ Auth mask (). Then (function (authData) {factory.authorized = AuthData.uid; // set the property here}). Hold (function (error) {});} // return it to factory;}); With this you will be referring to the factory reference and updates to your property (if you call the method that displays the data in your controller), the other way is the object. To back you will have to use the Gator's Function in your factory, or you can cache the promised return by the login function and return it and when an event occurs Programmed user logs out.
Comments
Post a Comment