在输入元素事件中添加debouncetime,angular10

在输入元素事件中添加debouncetime,angular10,angular,rxjs,Angular,Rxjs,我正在使用一个简单的角度输入 <ng-template #searchinput> <mat-form-field class="w-100" floatLabel="never"> <input matInput placeholder="Search" [id]="'search_'+col.columnDef&

我正在使用一个简单的角度输入

           <ng-template #searchinput>
              <mat-form-field class="w-100" floatLabel="never">
                <input matInput placeholder="Search" [id]="'search_'+col.columnDef" (input)="searchChange($event.target.value, col.columnDef)">
              </mat-form-field>
            </ng-template>

但这不起作用
错误类型错误:event.pipe不是函数
。需要一些帮助。

您的
事件实际上是输入字段中的值。如果要添加
debounceTime
,必须执行以下操作:

private value$ = new Subject<string>();

ngOnInit() {
  this.input$
    .pipe(
      debounceTime(300),
      distinctUntilChanged()
    )
    .subscribe((input: string) => {
      console.log(input);
    }
}

searchChange(input, colName) {
  this.input$.next(input);
}
private value$=新主题();
恩戈尼尼特(){
这是输入$
.烟斗(
去BounceTime(300),
distinctUntilChanged()
)
.subscribe((输入:字符串)=>{
控制台日志(输入);
}
}
searchChange(输入,colName){
this.input$.next(输入);
}

您的
事件
实际上是输入字段中的值

private value$ = new Subject<string>();

ngOnInit() {
  this.input$
    .pipe(
      debounceTime(300),
      distinctUntilChanged()
    )
    .subscribe((input: string) => {
      console.log(input);
    }
}

searchChange(input, colName) {
  this.input$.next(input);
}
private value$=新主题();
恩戈尼尼特(){
这是输入$
.烟斗(
去BounceTime(300),
distinctUntilChanged()
)
.subscribe((输入:字符串)=>{
控制台日志(输入);
}
}
searchChange(输入,colName){
this.input$.next(输入);
}

正确答案是Marek W的答案。另一种方法是使用FormControl,并对valueChanges进行subcribe

control=new FormControl();
ngOnInit()
{
 this.control.valueChanges.pipe(
      debounceTime(300),
      distinctUntilChanged()
    )
    .subscribe((input: string) => {
      console.log(input);
    }
}


正确答案是Marek W的答案。另一种方法是使用FormControl,并对valueChanges进行subcribe

control=new FormControl();
ngOnInit()
{
 this.control.valueChanges.pipe(
      debounceTime(300),
      distinctUntilChanged()
    )
    .subscribe((input: string) => {
      console.log(input);
    }
}



控制台说什么?错误是什么?添加了错误,事件基本上是无法观察到的文本证明正确答案将受到赞赏:)控制台说什么?错误是什么?添加了错误,事件基本上是无法观察到的文本证明正确答案将受到赞赏:)或者对输入使用
@viewChild
,然后使用
fromEvent()
直接从DOM事件创建流。FormControl给了你很多额外的东西,所以我最喜欢这个答案。我还认为,将FormControl与指令绑定看起来更干净、更容易理解。或者对输入使用
@viewChild
,然后使用
fromEvent()
直接从DOM事件创建流。FormControl给了你很多额外的东西,所以我最喜欢这个答案。我还认为将FormControl与指令绑定看起来更干净,更容易理解。