简体   繁体   English

未定义方法“ of”-Angular 5 HTTP服务教程

[英]Method “of” is not defined - Angular 5 HTTP services tutorial

I'am reading Angular 5 http tutorial . 我正在阅读Angular 5 http 教程 Everything worked fine, until I stuck on this weird construction wher my Ionic project is throwing error, that "of is not defined". 一切工作正常,直到我在Ionic项目抛出错误(“ of is not defined”)时停留在这个奇怪的构造上。

/**
* 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);
 };
}

I tired googling this "of" method, but with no success. 我厌倦了使用这种“ of”方法,但是没有成功。 Is this mistake in tutorial? 这是教程中的错误吗? Maybe some library? 也许有图书馆?

of is a separate function. of是一个单独的函数。 You need to import of function from rxjs package. 您需要导入of从功能rxjs包。 RxJS 5.5 and later use this technique with separate functions. RxJS 5.5和更高版本将此技术与单独的功能结合使用。 The most of functions you need to import, which lets you to have a clean code and also lets bundle tools to make some optimizations. 您需要导入的大多数功能都可以使您拥有简洁的代码,还可以捆绑工具进行一些优化。

import { of } from 'rxjs/observable/of'

As shown in example you need to import that method: 如示例所示,您需要导入该方法:

import { of } from 'rxjs/observable/of';

See here in page: 参见页面此处:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM