将 Angular 5 迁移到 Angular 7 [英] Migration Angular 5 to angular 7

查看:35
本文介绍了将 Angular 5 迁移到 Angular 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从 angular 5 迁移到了 Angular 7.在那之后,我的 RxJs 操作出现了问题,比如 observable 和我的 @ngrx/store.这是我的错误:

I have migrated from angular 5 to Angular 7. After that I have a problem with my RxJs operation like observable and my @ngrx/store. Here is my error:

ERROR in node_modules/@ngrx/store/src/actions_subject.d.ts(2,10): error TS2305: Module C:/Users/AbousyllabaNdiaye/Documents/amundi/ClientAmundiFileIntegration/node_modules/rxjs/BehaviorSubject"' has no exported member 'BehaviorSubject'.
node_modules/@ngrx/store/src/reducer_manager.d.ts(2,10): error TS2305: Module '"C:/Users/AbousyllabaNdiaye/Documents/amundi/ClientAmundiFileIntegration/node_modules/rxjs/BehaviorSubject"' has no exported member 'BehaviorSubject'.
node_modules/@ngrx/store/src/reducer_manager.d.ts(3,10): error TS2305: Module '"C:/Users/AbousyllabaNdiaye/Documents/amundi/ClientAmundiFileIntegration/node_modules/rxjs/Observable"' has no exported member 'Observable'.
node_modules/@ngrx/store/src/scanned_actions_subject.d.ts(2,10): error TS2305: Module '"C:/Users/AbousyllabaNdiaye/Documents/amundi/ClientAmundiFileIntegration/node_modules/rxjs/Subject"' has no exported member 'Subject'.
node_modules/@ngrx/store/src/state.d.ts(2,10): error TS2305: Module '"C:/Users/AbousyllabaNdiaye/Documents/amundi/ClientAmundiFileIntegration/node_modules/rxjs/BehaviorSubject"' has no exported member 'BehaviorSubject'.
node_modules/@ngrx/store/src/state.d.ts(3,10): error TS2305: Module '"C:/Users/AbousyllabaNdiaye/Documents/amundi/ClientAmundiFileIntegration/node_modules/rxjs/Observable"' has no exported member 'Observable'.
node_modules/@ngrx/store/src/store.d.ts(2,10): error TS2305: Module '"C:/Users/AbousyllabaNdiaye/Documents/amundi/ClientAmundiFileIntegration/node_modules/rxjs/Observer"' has no exported member 'Observer'.
node_modules/@ngrx/store/src/store.d.ts(3,10): error TS2305: Module '"C:/Users/AbousyllabaNdiaye/Documents/amundi/ClientAmundiFileIntegration/node_modules/rxjs/Observable"' has no exported member 'Observable'.
node_modules/@ngrx/store/src/store.d.ts(4,10): error TS2305: Module '"C:/Users/AbousyllabaNdiaye/Documents/amundi/ClientAmundiFileIntegration/node_modules/rxjs/Operator"' has no exported member 'Operator'.
node_modules/rxjs/BehaviorSubject.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/BehaviorSubject'.
node_modules/rxjs/Observable.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/Observable'.
node_modules/rxjs/Observer.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/Observer'.
node_modules/rxjs/Operator.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/Operator'.
node_modules/rxjs/Subject.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/Subject'.
src/app/habilitation/habilitation.component.ts(96,36): error TS2339: Property 'subscribe' does not exist on type 'Store<Principal>'.
src/app/sidebare/sidebare.component.ts(17,36): error TS2339: Property 'subscribe' does not exist on type 'Store<Principal>'.

推荐答案

您应该修复您的 Rxjs 导入.从 v6 开始,rxjs 的使用发生了一些相当大的变化.

You should fix your Rxjs imports. There are some pretty heavy change in the use of rxjs from v6 onwards.

尝试使用:import { BehaviorSubject } from 'rxjs';

与其他进口类似:

import { Observable } from 'rxjs';从'rxjs'导入{运算符};现在所有这些导出都是从 rxjs 完成的.你可以打开rxjs/index.d.ts查看rxjs的所有导出.

import { Observable } from 'rxjs'; import { Operator } from 'rxjs'; All these exports are done from rxjs now. You can open up rxjs/index.d.ts to see all exports of rxjs.

由于pipe 的变化以及与JavaScript 保留字 的冲突,一些操作符不得不重命名:

Due to the change with pipe and conflict with JavaScript reserved words, some operators had to be renamed :

  1. do 变成 tap
  2. catchfinally 变成 catchError finalize
  3. switch 变成 switchAll
  1. do becomes tap
  2. catch and finally become catchError finalize
  3. switch becomes switchAll

其他函数也被重命名:

  • fromPromise 变成 from
  • throw 变成 throwError
  • fromPromise becomes from
  • throw becomes throwError

这篇关于将 Angular 5 迁移到 Angular 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆