1

I use nodejs server to get data from an SQL database.

I would store data in taches which is an array of Tache :

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

}

When I print on console this taches I get result as :

undefined

When I print response.json() I get my values :

Object {taches: Array(8)}

So I delete .data and try again, then I get another error on line 1 of the template file :

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

here's my html file :

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

I would store data in taches array correctly so that I could show them as todo list.

1 Answer 1

1

try this:

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

your object received from the api holds the taches array

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.