1
我使用nodejs服务器从SQL数据库中获取数据。将Json数据从服务器存储到Angular 2中的数组中
我将存储在数据环节是环节存在的数组:
getTaches(): Observable<Tache[]> {
return this.http.get(this.tachesUrl)
.map(response => {
this.taches = response.json().data as Tache[];
console.log(this.taches);
})
.catch(this.handleError);
}
当我在控制台上打印这个环节我得到结果为:
undefined
当我打印response.json( )我得到我的价值观:
Object {taches: Array(8)}
所以我删除。数据,然后再试一次,然后我得到的TEMPL 1号线其他错误吃了文件:
ERROR Error: Error trying to diff '[object Object]'. Only arrays and iterables are allowed
,这里是我的html文件:
<md-toolbar color="primary">
<span>Taches non traitées</span>
</md-toolbar>
<md-card>
<md-list >
<ng-container *ngFor="let tache of this.tacheService.taches " >
<md-list-item *ngIf="tache.stat == 0" (click)="onSelect(tache)" [class.selectionnee]="tache === tacheSelectionnee">{{tache.stat}}+{{tache.id}} + {{tache.name}}
<div *ngIf="tache === tacheSelectionnee">
<button md-icon-button [mdMenuTriggerFor]="menu">
<md-icon>more_vert</md-icon>
</button>
<md-menu #menu="mdMenu">
<button md-menu-item (click)="openDialog(tache)">
<md-icon>edit</md-icon>
<span>Modifier</span>
</button>
<button md-menu-item (click)="delete(tache)">
<md-icon>delete</md-icon>
<span>Supprimer</span>
</button>
<button md-menu-item (click)="save(tache)">
<md-icon>cached</md-icon>
<span>Traiter</span>
</button>
</md-menu>
</div>
</md-list-item>
</ng-container>
</md-list>
</md-card>
我会正确地存储在阵列环节的数据,这样我就可以向他们的待办事项列表。
谢谢你,它的工作! –