DEV Community

Discussion on: Build an Angular 8 App with REST API and ASP.NET Core 2.2 - part 2

Collapse
 
melquimaillo profile image
Maíllo

Thanks Martin for your great article. I have been able to build my first CRUD in Angular. But now I'm stuck with the problem of including pagination with angular material. In the component we can get the observables (this.cargosPosts $ = this.cargoPostService.getCargoPosts ();) But how can I assign the data source to the pager?

I tried this, but don't run...

--- In the service
public lstCargos: Array = [];

getCargoPosts(): Observable {
this.http.get(this.myAppUrl + this.myApiUrlList).subscribe(result =>
{
this.lstCargos = result;
console.log(this.lstCargos)
}, error => console.error(error));

return this.http.get<Cargo[]>(this.myAppUrl + this.myApiUrlList)
  .pipe(
    map((lstCargos: Cargo[]) => lstCargos.map(cargo => this.getNewCargoFormatImg(cargo))),
    retry(1),
    catchError(this.errorHandler)
  );

}

---- In the component
this.cargosPosts$ = this.cargoPostService.getCargoPosts();
this.lstCargos = this.cargoPostService.lstCargos;
this.dataSource = new MatTableDataSource(this.lstCargos);

I'm very greatful if you can help me. Thankou very much