如何替换 Angular 中的 setTimeout

How to replace setTimeout in Angular

我想知道如何替换 Angular 中的 setTimeout()。

我有这样的东西

  public resetSelect: boolean = false;

  private clearSelection(): void {
    this.resetSelect = true;
    this.myForm.get('time').setValue(null);
    this.myForm.get('colors').setValue(null);
    this.myForm.removeControl('drinks');
    this.myForm.removeControl('food');

    setTimeout(() => {
      this.resetSelect = false;
    }, 200);
  }

resetSelect 设置为true,通过@Input()调用其他组件中的函数。

当您检测子组件本身的输入变化时,您可以将其设置为 false。

你可以使用 rxjs 定时器运算符

import {timer} from 'rxjs'

timer(200).subscribe(_=>{
  this.resetSelect = false;
})

但是我真的不知道你想达到什么目的