Angularjs promise not binding to template in 1.2
angularjs
Solution
There are changes in 1.2.0-rc3, including one you mentioned:
AngularJS 1.2.0-rc3 ferocious-twitch fixes a number of high priority issues in $compile and $animate and paves the way for 1.2. This release also introduces some important breaking changes that in some cases could break your directives and templates. Please be sure to read the changelog to understand these changes and learn how to migrate your code if needed. For full details in this release, see the changelog.
There is description in change log:
$parse:
- due to 5dc35b52, $parse and templates in general will no longer automatically unwrap promises. This feature has been deprecated and if absolutely needed, it can be reenabled during transitional period via `$parseProvider.unwrapPromises(true)` api.
- due to b6a37d11, feature added in rc.2 that unwraps return values from functions if the values are promises (if promise unwrapping is enabled - see previous point), was reverted due to breaking a popular usage pattern.
Problem
After upgrading to 1.2, promises returned by my services behave differently... Simple service myDates: ``` getDates: function () { var deferred = $q.defer(); $http.get(aGoodURL). success(function (data, status, headers, config) { deferred.resolve(data); // we get to here fine. })...... ``` In earlier version I could just do, in my controller: ``` $scope.theDates = myDates.getDates(); ``` and the promises returned from getDates could be bound directly to a Select element. Now this doesn't work and I'm forced to supply a callback on the promise in my controller or the data wont bind: ``` $scope.theDates = matchDates.getDates(); $scope.theDates.then(function (data) { $scope.theDates = data; // this wasn't necessary in the past ``` The docs still say: $q promises are recognized by the templating engine in angular, which means that in templates you can treat promises attached to a scope as if they were the resulting values. They (promises) were working in older versions of Angular but in the 1.2 RC3 automatic binding fails in all my simple services.... any ideas on what I might be doing wrong.