Angular2 - 如何显示稍后到达的数据

时间:2017-01-23 10:07:06

标签: angular

哦亲爱的角度为什么哦为什么......

我的git_list数组稍后到达。为什么我使用异步时出错?如果我不使用异步,那么当数据到达时,数据不会显示。

EXCEPTION: Uncaught (in promise): Error: Error in ./GitaccountsComponent class GitaccountsComponent - inline template:26:17 caused by: Invalid argument '' for pipe 'AsyncPipe'
Error: Invalid argument '' for pipe 'AsyncPipe'

<md-grid-tile *ngFor="let item of git_list  | async" [colspan]="1" [rowspan]="1">


</md-grid-tile>




 git_list = [
  {
    "git_account": "gggggggggg",
    "git_host": "bitbucket"
  },
  {
    "git_account": "yiofysdgsdgfs",
    "git_host": "bitbucket"
  },
  {
    "git_account": "yyyyyyyy",
    "git_host": "bitbucket"
  },
  {
    "git_account": "TTTTT",
    "git_host": "github"
  }
]

1 个答案:

答案 0 :(得分:0)

只需插入一个*ngIf就可以了,所以数据会在到达时放置而不会抛出错误。你必须在这里制作一个额外的div,因为两个指令不能放在一个标签中,而你已经*ngFor中有md-grid-tile,我只需要添加一个额外的div:< / p>

<div *ngIf="git_list" >
   <md-grid-tile *ngFor="let item of git_list" [colspan]="1" [rowspan]="1">
     <!-- Your code here --->
   </md-grid-tile>
</div>

希望这有帮助!