Angularjs承诺不绑定到模板在1.2

前端之家收集整理的这篇文章主要介绍了Angularjs承诺不绑定到模板在1.2前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
升级到1.2之后,我的服务返回的promise具有不同的行为…
简单服务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元素。
现在这不工作,我被迫提供一个回调的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自动绑定失败在所有我简单的服务….任何想法,我可能会做错了。

@H_404_19@
@H_404_19@
1.2.0-rc3有一些变化,包括你提到的一个:

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 07000.

更改日志中有描述:

$parse:

  • due to 07001,$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 @H_301_51@$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.
@H_404_19@ 原文链接:https://www.f2er.com/angularjs/146027.html

猜你在找的Angularjs相关文章