我正在阅读 Angular 5 http tutorial 。一切工作正常,直到我坚持这个奇怪的结构,我的 Ionic 项目抛出错误,即“未定义”。
/**
* Handle Http operation that failed.
* Let the app continue.
* @param operation - name of the operation that failed
* @param result - optional value to return as the observable result
*/
private handleError<T> (operation = 'operation', result?: T) {
return (error: any): Observable<T> => {
// TODO: send the error to remote logging infrastructure
console.error(error); // log to console instead
// TODO: better job of transforming error for user consumption
this.log(`${operation} failed: ${error.message}`);
// Let the app keep running by returning an empty result.
return of(result as T);
};
}
我厌倦了用谷歌搜索这个“of”方法,但没有成功。这是教程中的错误吗?也许是一些图书馆?
最佳答案
of
是一个单独的函数。您需要从 rxjs
包中导入 of
函数。 RxJS 5.5 及更高版本使用这种具有单独函数的技术。您需要导入的大部分函数,这可以让您拥有干净的代码,也可以让捆绑工具进行一些优化。
import { of } from 'rxjs/observable/of'
关于javascript - 方法 "of"未定义 - Angular 5 HTTP 服务教程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49751107/