2017-06-13 10 views
1

私はnodejsサーバーを使用してSQLデータベースからデータを取得します。Jsonデータをサーバーから配列に格納します。

IはTacheの配列であるtachesにデータを格納することになる:(Iはresponse.jsonを印刷するとき

undefined 

:私はコンソールに印刷する場合

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); 

} 

これは私はその結果を取得taches )私は私の値を得ます:

私は.dataを削除して、もう一度やり直してください

ERROR Error: Error trying to diff '[object Object]'. Only arrays and iterables are allowed 

はここに私のhtmlファイルです:私はToDoリストとしてそれらを表示することができるように

  <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> 

私が正しくtaches配列にデータを格納するファイルを食べました。

答えて

1

ことは、これを試してみてください。

getTaches(): Observable<Tache[]> { 
    return this.http.get(this.tachesUrl) 
     .map(response => { 
     this.taches = response.json().taches as Tache[]; 

    console.log(this.taches); 
}) 
    .catch(this.handleError); 
} 

あなたのオブジェクトは、APIから受け取ったtaches配列

+0

はそれが働いて、ありがとう保持しています! –

関連する問題