欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

node_modules/rxjs/Rx"' has no exported member 'of'

程序员文章站 2022-05-30 12:14:08
...

按照官方文档写代码

import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
//import { Observable } from 'rxjs/Observable';
//import 'rxjs/add/observable/of';
import {Hero} from './hero';
import {HEROS} from './mock-heros';


@Injectable()
export class HeroService {

  constructor() { }
  
  //获取英雄列表
  getHeros(): Observable<Hero[]> {
	return of(HEROS);
  }

}


但Angular编译失败,报错

node_modules/rxjs/Rx&amp;amp;quot;' has no exported member 'of'
后来在rxjs帮助文档中找到解决办法;

http://reactivex.io/rxjs/manual/installation.html

node_modules/rxjs/Rx&amp;amp;quot;' has no exported member 'of'


正确代码如下:

import { Injectable } from '@angular/core';
//import { Observable, of } from 'rxjs';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import {Hero} from './hero';
import {HEROS} from './mock-heros';


@Injectable()
export class HeroService {

  constructor() { }
  
  //获取英雄列表
  getHeros(): Observable<Hero[]> {
	return Observable.of(HEROS);
  }

}