错误错误:尝试与'nombreyo'进行比较时出错。仅允许数组和可迭代项

时间:2019-12-05 13:04:24

标签: angular typescript httpclient angular8

尝试在html中绘制类时出现此错误

<li>
    <ul>
      <li *ngFor="let refac of refactormodel" >
        -- word_to_rename: {{refac.word_to_rename}}
        -- renowned_word: {{refac.renowned_word}}
         -- name: {{refac.name}}
      </li>
    </ul>     
  </li>

我希望如果类为空,则不绘制它,但是是的,并且在绘制它时会出现该错误: 错误错误:尝试与'nombreyo'进行比较时出错。仅允许数组和可迭代对象

private refactormodel : getrefactormodel[] = [];

....

this.authService.getrefactor().subscribe((res : getrefactormodel[])=>{
        this.refactormodel = res;
      });

 getrefactor() {
          return this.http.get(apiUrl + 'getRules');
         
      } 

refactormodel.ts:

export interface getrefactormodel {
      word_to_rename: String;
      renowned_word: String;
      name: String;

    }

1 个答案:

答案 0 :(得分:0)

您已经尝试过这样吗?:

  <li *ngFor="let refac of refactormodel" >{{ '-- word_to_rename' + refac.word_to_rename + '...further text fragments...' }}
  </li>