Automatic unwrapping of promises by $parse severely limits its usefulness
The behavior introduced by 3a65822, which automatically unwraps promises returned by functions invoked by $parse, prevents any consumer of an expression from handling promise resolution on its own. More pertinent discussion of the problem exists here: #3503
Notably this breaks the typeahead directive in UI bootstrap, as per this issue: angular-ui/bootstrap#949
Here's a simple example of why this change is problematic.
http://plnkr.co/edit/ymxbpR?p=preview
The directive in that plunk executes a function on click (in the same way as ng-click) and expects a promise to be returned, which it will use to decorate the link with loading text.
Because $parse unwraps the promise, the directive has no chance to add its own handlers. If you switch the Angular version to 1.2.0rc1, it works as expected. I don't believe this is an uncommon use case, and certainly not one the framework should prevent from being possible. I hope this can be resolved by the next RC.
That's true, but I liked the conciseness of the deprecated functionality. Would be nice to have both conciseness and explicitness.
Just inject the above function to your $rootScope using a name of your choice, et voila!
I understand this, but promises are an important concept across the framework, and so having a special support for them in expressions seems logical and consistent. At least for me. Also this support would make it somewhat easier for people new to Angular to start using promises.
It may seem to be helpful to beginners but in reality it will cause confusion later on and it's much better to unwrap manually from the off. On 23 Oct 2013 15:33, "thorn0" [email protected] wrote:
I understand this, but promises are an important concept across the framework, and so having a special support for them in expressions seems logical and consistent. At least for me. Also this support would make it somewhat easier for people new to Angular to start using promises.
— Reply to this email directly or view it on GitHubhttps://github.com/angular/angular.js/issues/4158#issuecomment-26909760 .
+1 to to a special operator or providing an unwrap function by default. This just saves typing in simple cases (and a lot of cases are simple). What exactly do I gain from
$scope.numbers = undefined; service.getNumbers().then(function(numbers) { $scope.numbers = numbers; });
as opposed to
$scope.numbers = service.getNumbers()
??? I don't mind making the unpacking explicit in the templates.