Home > Mobile >  Converting from do() to tap() from Angular 2 to Angular 6
Converting from do() to tap() from Angular 2 to Angular 6

Time:02-08

I am trying to implement Server Side Pagination for a Grid in Angular 6 with Kendo Grid

The code below is from Angular 2 which I have taken from the below site

https://www.c-sharpcorner.com/article/server-side-paging-in-kendo-grid-for-angular-2/

public ngAfterViewInit(): void {  
  this.grid.dataStateChange  
      .do(({ skip, take }: DataStateChangeEvent) => {  
          this.skip = skip;  
          this.pageSize = take;  
      })  
      .subscribe(x => this.service.query(x));  
}

Because I am using Angular 6, it is expecting tap instead of do in the above code.

Currently I am getting red swiggly for do and the error says as below

Property 'do' does not exist on type 'EventEmitter<DataStateChangeEvent>'

How can I convert it into a usable code by using tap here?

CodePudding user response:

For tree shaking purposes RxJS changed its synthax from 6.0 upwards.

public ngAfterViewInit(): void {  
  this.grid.dataStateChange
      .pipe(
          tap(({ skip, take }: DataStateChangeEvent) => {  
              this.skip = skip;  
              this.pageSize = take;  
          })
      ) 
      .subscribe(x => this.service.query(x));  
}
  •  Tags:  
  • Related