afficher api web dans une mat-tabledata

3 views
Skip to first unread message

Mhamed B

unread,
Jul 11, 2022, 1:04:33 AM7/11/22
to FrAngular - AngularJS en français
Bonjour
j'ai créer api web dot net core, aprés je suis avec  mat table pour afficher en tableau les donnees d api, le service marche aussi.
malheureusement cette dernière n'affiche rien et lapi marche
merci de m'aider
voici le code
componnent.ts
 ngOnInit() {
                   this.getAllContrat()
                }
                getAllContrat() {
                  this.contrat =  this.service.getContrat()
                  .pipe(take(1)) // notice take(1) to unsubscribe observable  
                  .subscribe((res:any) =>{
                    this.dataSource = new MatTableDataSource(res);
          //            this.contrat = res
                   
                  }
                 
                  )
                  //this.dataSource.data = this.contrat;
                 /*this.http.get<Contrat>('https://localhost:44363/api/Contrat/GetAllContrat')
                 .subscribe(result=>{
                  this.contrat = result;}
                  ,error => console.error(error));*/
                //this.service.getContrat()
                 
                  //  this.dataSource.data=this.dataArray;
        
                  }

en html
<div class="mat-elevation-z8">
        <mat-table [dataSource]="dataSource"  matSort>
          <ng-container matColumnDef="ID">
            <mat-header-cell *matHeaderCellDef  mat-sort-header>ID</mat-header-cell>
            <mat-cell *matCellDef="let element">{{element.ID}}</mat-cell>
          </ng-container>
        <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
        <mat-row *matRowDef="let row; column:displayedColumns;"></mat-row>
    </mat-table>
</div>  
Reply all
Reply to author
Forward
0 new messages