我正在关注本Material data table tutorial教程,该教程实现了可观察的表格过滤。
我想修改此代码以仅在按回车键时才进行分页。
fromEvent(this.input.nativeElement,'keyup')
.pipe(
debounceTime(150),
distinctUntilChanged(),
tap(() => {
this.paginator.pageIndex = 0;
this.loadLessonsPage();
})
)
.subscribe();
我试图在按下“ Enter”键而不是任何键时发出fromEvent。
答案 0 :(得分:1)
您可以使用过滤器运算符:
fromEvent(this.input.nativeElement,'keyup')
.pipe(
debounceTime(150),
filter((e: KeyboardEvent) => e.keyCode === 13),
distinctUntilChanged(),
tap(() => {
this.paginator.pageIndex = 0;
this.loadLessonsPage();
})
)
.subscribe();