javascript - Return nested promise to parent function -
I have seen that the result of the promise chains is the changing of a scope variable in most angle tutorials.
$ http.get (someURL). Then (function (value) {$ scope.someValue = value;});
Is it possible to return the original value? Anytime I have tried another promise gives back.
$ scope.test = function () {$ http.get (someURL) back. Then (work (value) {return value;}); }; $ Scope.test = function () {var deferred = $ q.defer (); $ Http.get (someURL). Then (function (value) {deferred.resolve (value);}); Refund refund. }
I do not want to match any other promise, just return Jason so that I can do something like this:
& lt; Button ng-click = 'some_vars = test ()' & gt; Get AJAX & lt; / Button & gt; & Lt; Ul ng-repeat = 'var_vars in var' & gt; & Lt; Li & gt; {{Var.title}} & lt; / Li & gt; & Lt; / Ul & gt;
IMO should do the following:
Your Controller It does:
$ scope.some_vars = []; $ Scope.loadVars = function () {$ http.get (someURL) .sevate (function) {$ scope.some_vars = data;}); };
Do this in your opinion:
& lt; Button ng-click = 'loaders ()' & gt; Get AJAX & lt; / Button & gt; & Lt; Ul ng-if = "some_vars.length> 0" ng-repeat = 'in some some_vars' & gt; & Lt; Li & gt; {{Var.title}} & lt; / Li & gt; & Lt; / Ul & gt;
Very easy, right?
However if you are using the angular version before 1.2.0-rc.3. and you really want to open automatically to open promises ( I will strongly advise you against it) , you will see Prompt Opening was removed with version 1.2 and it has been completely degraded with version 1.2.0-rc.3. You can view this document:. $ parse: Due to fa6e411d, the promise has been canceled. It has been removed since 1.2.0-RC.3. It can not be started now Two methods have been removed: $ parseProvider Change the settings of:
.config (function ($ parseProvider) {$ parseProvider.unwrapPromises (true);})
$ parseProvider.unwrap $ parseProvider.logPromiseWromings
Comments
Post a Comment