Comment voulez-vous attraper l'erreur dans ce cas:Comment voulez-vous attraper l'erreur
getStuff(): Observable<Stuff[]> {
return this.http.get(url)
.map((res: Response) => {
return res.json()
.map(item => {
return {
id: item.id
name: item.code
};
});
});
}
J'ai essayé de mettre .catch()
mais en disant ce type de retour ne correspond pas à Supplied parameters do not match any signature of call target.
getStuff(): Observable<Stuff[]> {
return this.http.get(url)
.map((res: Response) => {
return res.json()
.map(item => {
return {
id: item.id
name: item.code
};
});
})
.catch();
}
avec .catch((err) => console.error(err));
obtenir Argument of type '(err: any) => void' is not assignable to parameter of type '(err: any, caught: Observable<any>) => ObservableInput<{}>'. Type 'void' is not assignable to type 'ObservableInput<{}>'.
essayer '.catch ((err) => console.error (err))' – Jerry06
@ Jerry06 avec celui-ci 'argument de type « (err: any) = > void 'n'est pas assignable au paramètre de type' (err: any, catch: Observable) => ObservableInput <{}> '. Le type 'void' n'est pas assignable au type 'ObservableInput <{}>' ' –
sreginogemoh
Le' .catch() 'comme dans' Observable.catch() 'n'est valable qu'après le' .map() 'initial. Donc '.get(). Map(). Catch()' dans la chaîne observable. Le vôtre est au mauvais endroit. –