gpt4 book ai didi

javascript - 方法 "of"未定义 - Angular 5 HTTP 服务教程

转载 作者:行者123 更新时间:2023-11-28 11:30:38 25 4
gpt4 key购买 nike

我正在阅读 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com