Angular 7承诺正在发挥作用吗?进行成功阻止,一次犯错

时间:2018-12-17 06:32:24

标签: angular angular-promise angular7 angular-httpclient

我正在将应用程序Angular 2(Http)转换为Angular 7(HttpClient) 我不明白为什么这样工作。我的代码

     service.ts

  return this.http.get(serviceUrl).toPromise().then((data:any) => {
            return data;
        })

component.ts

this.myService.getList()
    .then((rmanFmvRulesDefList: any) => {
      $.unblockUI();
      console.log('list',rmanFmvRulesDefList);
      this.datasource = rmanFmvRulesDefList.content;
      this.rmanFmvRulesDefList = rmanFmvRulesDefList.content;


      if (this.rmanFmvRulesDefList.length > 0) {

        for (let i = 0; i < rmanFmvRulesDefList.content.length; i++) {
          this.rmanFmvRulesDefList1.push({
            'fmvRuleName':  rmanFmvRulesDefList.content[i].fmvRuleName,
            'fmvCategory':  rmanFmvRulesDefList.content[i].fmvCategory
          })
        }

        /*  for (let i = 0; i < rmanFmvRulesDefList.content.length; i++) {
        this.rmanFmvRulesDefList1.push({
          'fmvRuleName':  rmanFmvRulesDefList.content[i].fmvRuleName,
          'fmvCategory':  rmanFmvRulesDefList.content[i].fmvCategory,
          'fmvType': rmanFmvRulesDefList.content[i].fmvType,
          'fmvRuleStatus':  rmanFmvRulesDefList.content[i].fmvRuleStatus,
          'fmvPrice':  rmanFmvRulesDefList.content[i].fmvPrice ,
          'min':  formatNumber(rmanFmvRulesDefList.content[i].min , '1.2-2'),
          'median': formatNumber(rmanFmvRulesDefList.content[i].median , '1.2-2'),
          'max': formatNumber(rmanFmvRulesDefList.content[i].max , '1.2-2')
        })
      }*/ 
      }

      console.log(this.rmanFmvRulesDefList1, 'rman fm list')

    }).catch((err: any) => {
      console.log('erre block')
          this.growlMsgs=[{severity:'error', summary:'Error Message', detail:'Error occured while getting data!!'}];
           $.unblockUI();
       });

我从服务中获得了100个列表项

问题:在这种情况下,我的成功(然后),错误(然后)块一次被调用

  1. 如果我准备具有两个属性的数组(this.rmanFmvRulesDefList1),就可以正常工作

    2。但是,如果我准备具有8个属性的数组,它将进入catch块,并执行代码

    请任何人帮助我这里发生的事情

0 个答案:

没有答案