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

标签 javascript angular typescript ionic-framework

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

相关文章:

javascript - IE的removeNode相当于什么

javascript - 我想在 javascript 中获取没有 ClientId 的变量中的元素

html - 如何使用 ionic 制作 pdf 生成器?

angular - 在不共享同一父组件的子组件之间共享 Angular 2 服务

Javascript:alert ('...' ) - 错误:未捕获的异常:ReferenceError:未定义警报

嵌套服务中的 Angular 嵌套可观察对象 - 如何

node.js - Angular 4 中的数组推送导致浏览器卡住/卡住。如何解决此问题?

javascript - 如何模拟使用在 Node 模块中导出的导入(ES6 typescript)进行单元测试的外部注入(inject)库

javascript - 处理 HTTP 请求失败

javascript - "X-Requested-With" header 已设置,但未在 php 中设置