0
기반으로 관찰 가능한 체인의 실행을 중지, 내 부품이 관찰 가능한 체인이 있습니다각도 응용 프로그램에서 조건
@Component({
selector: 'app-search',
templateUrl: './search.component.html',
styleUrls: ['./search.component.css']
})
export class SearchComponent implements OnInit {
search.component.ts
results: any[] = [];
queryField: FormControl = new FormControl();
constructor(private _apiService: ApiService) { }
ngOnInit() {
this.queryField.valueChanges
.debounceTime(200)
.distinctUntilChanged()
.switchMap((query) => this._apiService.search(query)) // was subscribe
.subscribe(result => { this.results = result.items; console.log(result); });
} }
seach.ccomponent.html
<input [formControl]='queryField' type="text" id="keyword" autocomplete="off" placeholder="start typing..."/>
Observables 체인의 나머지 실행을 취소하고 switchMap 연산자로 이동하지 마십시오 (요청을 실행하지 않기 위해). 값이 du formControl은 null입니다.