【发布时间】:2022-04-21 20:07:20
【问题描述】:
我想通过get Http 调用从我的后端获取customers 列表。但我无法在我的component 中声明customers 的array。
我有这样的customer.interface.ts
export interface Customer {
_id?: string,
name: string,
email: string,
phone?: string,
address?: string,
age?: number
}
我有 http.service.ts
get = (url: string): Observable<any> => {
return this.http.get(this.createUrl(url), { headers: this.getHeaders() });
}
在我的 customer.service.ts 中
getCustomers(): Observable<Customer[]>{
return this._http.get(ApiConstants.getCustomers);
}
在我的 customer.component.ts 中
customers$: Observable<Customer[]> = [];
ngOnInit(){
this.customers$ = this.customerService.getCustomers();
}
现在它在这一行 customers$: Observable<Customer[]> = [] 上给了我一个错误,就像在编译时在编辑器中一样。
Type 'never[]' is missing the following properties from type 'Observable<Customer[]>': isScalar, source, operator, lif and 5 more
这里有什么问题?
【问题讨论】:
标签: angular typescript http