【发布时间】:2021-08-15 12:46:33
【问题描述】:
我正在尝试 Angular 的自动完成功能,但我一直遇到 CORS 错误。 其他 API 调用工作正常。
我遇到了this,但它不是很有用。
下面是我的实现
ngOnInit(): void {
const url = this.setupApiUrl + "GetBranches/";
this._dataService.SetHeaders()
this.branchNameCtrl.valueChanges
.pipe(
debounceTime(2000),
tap(() => {
this._dataService.SetHeaders();
this.errorMsg = "";
this.branchList = [];
this.isLoading = true;
}),
switchMap(value => this._dataService.GetResults<BranchViewModel>(url + value)
.pipe(
finalize(() => {
this.isLoading = false
}),
)
)
)
.subscribe(data => {
if (data.result['Search'] === undefined) {
this.errorMsg = data.result['Error'];
this.branchList = [];
} else {
this.errorMsg = "";
this.branchList = data.result['Search'];
} console.log(this.branchList);
});
}
【问题讨论】:
标签: angular typescript autocomplete angular-material .net-core-angular