加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angularjs承诺不绑定到模板在1.2

发布时间:2020-12-17 08:44:41 所属栏目:安全 来源:网络整理
导读:升级到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.
升级到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自动绑定失败在所有我简单的服务….任何想法,我可能会做错了。

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读