angularjs - Assign value to the Factory variable through http -
I have two controllers and one factory. I am making an angular plan for the module for authentication.
UserFactory.js
myApp.factory ('Userfactory', function (at, $ location) {var Userfactory = {} Userfactory.user = [] Userfactory.active = False Userfactory.isLogged = function (if (! Userfactory.active [0]) {return Auth.currentUser (). Then (function (user) {Userfactory.user.push (user) Userfactory.active = angular.copy UserController.js myApp.controller ("userController"); , Function ($ scope, Userfactory) {Userfactory.isLogged (). Then (function () {$ scope.active = Userfactory.active;}}} NavController.js
myApp.controller ("navController", function navController (Userfactory) {this.user = Userfactory.user; this.active = U Serfactory.active;}) User controller NAV controller is not updated, when the update is updated, because the value is reset (which binding breaks), where as the user controls the form Mana is promised, so it is getting the latest value. My suspicion is how it is managed to work in both places, which means how to specify the value without breaking the bond.
Declaring a workaround userfactory.active as an array and rejecting the value as correct or false, but finding a better way to do it, any help would be helpful .
I use the model object to wrap all the variables / properties I recommend you to be bindable. MyApp.factory ('UserFactory', function (ath, $ location) {var UserFactory = {} Userfactory.model = {user: undefined, active: wrong}; Userfactory.isLogged = function () (if (! Userfactory.active [ 0]) {return Auth.currentUser (). Then (function (user) {Userfactory.model.user = user; Userfactory.model.active = true;}, function (error) {});}} userfactor;}) and then on your controllers:
myApp.controller ("userController", function ($ scope, Userfactory) {userfactory.isLogged (). (Function () {$ scope.userModel = Userfactory.model; // and on UI usage: userModel.active})} myApp.controller ("navContr oler", function new rule Control (userfonder) {this.userModel = Userfactory.model; // then like it: this.userModel.active})
Comments
Post a Comment