aru*_*run 22 rxjs angular angular5
我正在从教程(https://angular.io/tutorial/toh-pt4#inject-message-service)学习新的角度.在添加服务后运行应用程序时我陷入了困境
../node_modules/rxjs/Rx"'没有''的导出成员'.
hero.service.ts
---------------------
import { Injectable } from '@angular/core';
// import { Observable, of } from 'rxjs';
import { Observable, of } from 'rxjs/Observable';
import { Hero } from './hero';
import { HEROES } from './mock-heroes';
import { MessageService } from './message.service';
@Injectable()
export class HeroService {
constructor(private messageService: MessageService) { }
getHeroes(): Observable<Hero[]> {
// TODO: send the message _after_ fetching the heroes
this.messageService.add('HeroService: fetched heroes');
return of(HEROES);
}
}
Run Code Online (Sandbox Code Playgroud)
我的Angular版本和相关信息是
Angular CLI: 1.7.4
Node: 6.14.1
OS: linux x64
Angular: 5.2.10
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.7.4
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.5.3
webpack: 3.11.0
@angular/cli: 1.7.4
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.5.
Run Code Online (Sandbox Code Playgroud)
Nil*_*dri 63
从你的代码看起来你是以下这是基于角6和Rxjs 6.有在Rxjs重大更改您具有导入角官方指南operators,并Observable在现在以不同的方式.
在Rxjs 6中,导入如下 -
import { Observable, of } from 'rxjs'; // only need to import from rxjs
Run Code Online (Sandbox Code Playgroud)
但是当您使用Angular 5.2.x时,您很可能仍在使用Rxjs 5x版本.因此,您的import语句应如下所示
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
// or
import { of } from 'rxjs/observable/of';
Run Code Online (Sandbox Code Playgroud)
请查看以下链接以获取完整的更改日志以及安装兼容包rxjs-compat以从角度5升级到6的说明.
请参阅此链接以供参考:https://www.academind.com/learn/javascript/rxjs-6-what-changed/
| 归档时间: |
|
| 查看次数: |
25013 次 |
| 最近记录: |