Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Automatically resolve promises #10956

Closed
nkt opened this issue Feb 4, 2015 · 4 comments
Closed

Automatically resolve promises #10956

nkt opened this issue Feb 4, 2015 · 4 comments

Comments

@nkt
Copy link

nkt commented Feb 4, 2015

I want to suggest automatically resolve promises inside ng-repeat, ng-bind and other directives with the same behavior.
Now I have to write something in this way:

$http.get('/api/users').success(function(users) {
    $scope.users = users;
});

It would be better to replace this with:

$scope.users = $http.get('/api/users');
@matsko
Copy link
Contributor

matsko commented Feb 4, 2015

This used to be the case early on with Angular (something called Promise unwrapping), but it lead to a lot of issues. There's a full description here as to why it was removed: #4317

@pkozlowski-opensource
Copy link
Member

This used to work as you are proposing and was removed later on as it was causing all sort of confusion and corner cases (ex.: what to do when a promise fails?). I don't think we want to go back on this one.

@nkt
Copy link
Author

nkt commented Feb 4, 2015

@pkozlowski-opensource promises allows to chain methods:

$scope.users = $http.get('/api/users').error((e) => console.error(e));

@lgalfaso
Copy link
Contributor

lgalfaso commented Feb 4, 2015

@nkt as @pkozlowski-opensource stated before, this was the original behavior in Angular 1.0, this behavior caused too many issue and side-effects that developers were not expecting. The current behavior is simpler to understand and works better. You just have to do

$http.get(...).then(
function(users) {
  $scope.users = users;
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants