javascript - $http promise not updating scope (ng-hide) -
What I'm trying to achieve here, is getting a request for my API, which is true / Responding with the wrong, whether the user is logged in or not, ideally I want to hide the entry form if the user is logged in. I am using Angel in the HTTP method, which gives a promise and what I think is already wrapped in $ $, so I would have thought that the scope would be automatically updated.
My Controller:
.controller ('MyCtrl1', ['$ scope', 'isLoggedIn', '$ timeout', function ($ scope, IsLoggedIn, $ Timeout} {isLoggedIn.getState (). Then (function (result) {$ scope.displayLogin = result.data.state;}); $ scope.getLoginState = function () {console.log ($ scope. DisplayLogin); }}]); My service:
.factory ('isloggedIn', function ($ http, $ q) {return} {getState: function (scope) { Return $ Http.get ('/ login-state'). Then (function (result) {return result})}}}}) html:
& lt; Form method = "most" action = "/ login" ng-hide = "display login" & gt; I know that the value is being updated because I have a button, which comes with NG click, which is linked to the getLoginState method, which displayLogin with the correct value Does it seem that the NG-hide does not reflect this? As the scope is not aware of change.
How can I work for this, so hide the value of my reality?
Depending on your code, you think that your factory has $ http service Let's promise to return to the promise? factory ('isLoggedIn', function ($ http, $ q) {return} {getState: function (scope) {return $ http.get ('/ login-state');} }});
Comments
Post a Comment