0
我有这个API函数皮棉错误:角2无法解析HTTP调用
getBrands(params?: any): Observable<IBrand[]> {
return this.http.get(Host + endpoints.brands, params)
.map((res: Response) => res.json() as IBrand[])
.catch((error: any) => {
this.notifications.show({message: 'Kunde inte hämta märken', theme: 'danger'});
return error || 'Server fel';
});
}
它通过从外部API获取数据很好,但我得到我解决不了两个皮棉错误我的生活。
第一个是这样的:
Type 'Observable<{}>' is not assignable to type 'Observable<IBrand[]>'.
Type '{}' is not assignable to type 'IBrand[]'.
Property 'find' is missing in type '{}'.
,第二个是Supplied parameters do not match any signature of call target
它来源于此行.map((res: Response) => res.json() as IBrand[])
。
为什么我会得到这些错误,我该如何解决它们?
编辑:根据要求
IBrand
接口:
export class IBrand {
id?: string;
name?: string;
isActive?: boolean;
image?: string;
}
您是否试过'返回> this.http.get(Host + endpoints.bran..'? –
echonax
您可以发布您的代码为'IBrand'吗? – Michael
您正在使用哪个IDE,有时重新启动IDE工作,或者尝试使用rxjs的ToPromise()扩展而不是可观察的方式返回promise,或者是否导入'rxjs/Rx';? –