【问题标题】:equivalent of following code in angular 2相当于 Angular 2 中的以下代码
【发布时间】:2019-06-20 08:09:06
【问题描述】:

我无法从 angularjs ad angular 2 更新此代码,感谢您的帮助

 if (settings != null && settings.checkSubscriptionForVip === true) {
            return this.user.hasVipAccess().then(function(hasVipAccess) {

              hasVipAccess ? deferred.resolve() : deferred.reject("NO_VIP");
              return;
            });
          } else {
            deferred.resolve();
            return;
          }

【问题讨论】:

    标签: angularjs angular ionic-framework


    【解决方案1】:

    您需要在组件中定义一个布尔变量并将结果分配给该变量,

    hasVipAccess : boolean = false;
    
    if (settings != null && settings.checkSubscriptionForVip === true) {
                this.user.hasVipAccess().then(function(access) {
                   this.hasVipAccess = access;               
                });
              } else {
              this.hasVipAccess = access;
     }
    

    但是如果你不需要设置布尔变量,只需返回结果

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-08
      • 2018-01-24
      • 1970-01-01
      • 2015-01-29
      • 2018-08-19
      • 2017-07-19
      • 2019-02-08
      • 2015-11-14
      相关资源
      最近更新 更多