升级到1.2之后,我的服务返回的promise具有不同的行为…
@H_404_1@简单服务myDates:
getDates: function () { var deferred = $q.defer(); $http.get(aGoodURL). success(function (data,status,headers,config) { deferred.resolve(data); // we get to here fine. })......
在早期版本中我只能做,在我的控制器:
$scope.theDates = myDates.getDates();
并且从getDates返回的promise可以直接绑定到Select元素。@H_404_1@现在这不工作,我被迫提供一个回调的promise在我的控制器或数据不绑定:
$scope.theDates = matchDates.getDates(); $scope.theDates.then(function (data) { $scope.theDates = data; // this wasn't necessary in the past
文档仍然说:
$ q promises由模板引擎在角度中识别,这意味着在模板中,您可以将附加到作用域的promise视为结果值。
他们(承诺)在旧版本的Angular工作,但在1.2 RC3自动绑定失败在所有我简单的服务….任何想法,我可能会做错了。
1.2.0-rc3有一些变化,包括你提到的一个:
原文链接:https://www.f2er.com/angularjs/146027.htmlAngularJS 1.2.0-rc3 ferocIoUs-twitch fixes a number of high priority@H_404_1@ issues in $compile and $animate and paves the way for 1.2.@H_404_1@ This release also introduces some important breaking changes that in some cases could break your directives and templates. Please@H_404_1@ be sure to read the changelog to understand these changes and learn@H_404_1@ how to migrate your code if needed.@H_404_1@ For full details in this release,see the 07000.
更改日志中有描述:
$parse:
- due to 07001,$parse and templates in general will no longer automatically unwrap promises. This feature has been deprecated and@H_404_1@ if absolutely needed,it can be reenabled during transitional period@H_404_1@ via
$parseProvider.unwrapPromises(true)
api.- due to 07002,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.