Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 6自动建议搜索框_Angular_Typescript_Rxjs - Fatal编程技术网

Angular 6自动建议搜索框

Angular 6自动建议搜索框,angular,typescript,rxjs,Angular,Typescript,Rxjs,我一直在学习这个教程,我想在angular 6中完成它 如何将其转换为与angular 6兼容的代码 ngOnInit() { this.queryField.valueChanges .debounceTime(200) .distinctUntilChanged() .switchMap((query) => this._searchService.search(query)) .subscribe( result => { if (re

我一直在学习这个教程,我想在angular 6中完成它

如何将其转换为与angular 6兼容的代码

ngOnInit() {
    this.queryField.valueChanges
    .debounceTime(200)
    .distinctUntilChanged()
    .switchMap((query) =>  this._searchService.search(query))
    .subscribe( result => { if (result.status === 400) { return; } else {   this.results = result.json().artists.items; }
  });
  }
}
我自己转换了这个,但在this.logframe.searchEmployee(term.subscribe()

如果您对此有其他选择,请让我知道:)

编辑: 修复了我的问题:)

我只需要通过获得特定的formcontrol来调整Fan Cheung代码,然后还添加catcherror,这样它就不会在null上的404之后完成

ngOnInit() {
    this.registerationForm.get('name').valueChanges
    .pipe(
      debounceTime(200),
      distinctUntilChanged(),
      switchMap((term) => this.logframe.searchEmployee(term).pipe(catchError(err => of('null')))),
    ).subscribe(
      val => console.log(val)
    );
  }
ngOnInit() {
    this.registerationForm.get('name').valueChanges
    .pipe(
      debounceTime(200),
      distinctUntilChanged(),
      switchMap((term) => this.logframe.searchEmployee(term).pipe(catchError(err => of('null')))),
    ).subscribe(
      val => console.log(val)
    );
  }

订阅返回
Subscription
不能被
switchMap
如果
this.logframe.searchEmployee(term)
返回可观察值,请尝试下面的代码

ngOnInit() {
    this.registerationForm.valueChanges
    .pipe(
      debounceTime(200),
      distinctUntilChanged(),
      switchMap((term) => this.logframe.searchEmployee(term)),
    );
  }
修复了我的问题:)

我只需要通过获得特定的formcontrol来调整Fan Cheung代码,然后还添加catcherror,这样它就不会在null上的404之后完成

ngOnInit() {
    this.registerationForm.get('name').valueChanges
    .pipe(
      debounceTime(200),
      distinctUntilChanged(),
      switchMap((term) => this.logframe.searchEmployee(term).pipe(catchError(err => of('null')))),
    ).subscribe(
      val => console.log(val)
    );
  }