将带有rxjs的angular 5模块导入angular 8应用程序
我正在尝试将Angular 5中制作的模块导入Angular 8项目 当我试图把它端上来时,我犯了一系列错误:将带有rxjs的angular 5模块导入angular 8应用程序,angular,rxjs,Angular,Rxjs,我正在尝试将Angular 5中制作的模块导入Angular 8项目 当我试图把它端上来时,我犯了一系列错误: [ng] ERROR in ./node_modules/ngx2048/node_modules/@angular/core/esm2015/core.js [ng] Module not found: Error: Can't resolve 'rxjs/Observable' in 'C:\Users\JB\Dropbox\dev\battle2048\node_modules\
[ng] ERROR in ./node_modules/ngx2048/node_modules/@angular/core/esm2015/core.js
[ng] Module not found: Error: Can't resolve 'rxjs/Observable' in 'C:\Users\JB\Dropbox\dev\battle2048\node_modules\ngx2048\node_modules\@angular\core\esm2015'
[ng] ERROR in ./node_modules/ngx2048/node_modules/@angular/core/esm2015/core.js
[ng] Module not found: Error: Can't resolve 'rxjs/Subject' in 'C:\Users\JB\Dropbox\dev\battle2048\node_modules\ngx2048\node_modules\@angular\core\esm2015'
[ng] ERROR in ./node_modules/ngx2048/node_modules/@angular/core/esm2015/core.js
[ng] Module not found: Error: Can't resolve 'rxjs/Subscription' in 'C:\Users\JB\Dropbox\dev\battle2048\node_modules\ngx2048\node_modules\@angular\core\esm2015'
[ng] ERROR in ./node_modules/ngx2048/node_modules/@angular/forms/esm2015/forms.js
[ng] Module not found: Error: Can't resolve 'rxjs/observable/forkJoin' in 'C:\Users\JB\Dropbox\dev\battle2048\node_modules\ngx2048\node_modules\@angular\forms\esm2015'
[ng] ERROR in ./node_modules/ngx2048/node_modules/@angular/forms/esm2015/forms.js
[ng] Module not found: Error: Can't resolve 'rxjs/observable/fromPromise' in 'C:\Users\JB\Dropbox\dev\battle2048\node_modules\ngx2048\node_modules\@angular\forms\esm2015'
[ng] ERROR in ./node_modules/ngx2048/node_modules/@angular/core/esm2015/core.js
[ng] Module not found: Error: Can't resolve 'rxjs/observable/merge' in 'C:\Users\JB\Dropbox\dev\battle2048\node_modules\ngx2048\node_modules\@angular\core\esm2015'
[ng] ERROR in ./node_modules/ngx2048/node_modules/@angular/forms/esm2015/forms.js
[ng] Module not found: Error: Can't resolve 'rxjs/operator/map' in 'C:\Users\JB\Dropbox\dev\battle2048\node_modules\ngx2048\node_modules\@angular\forms\esm2015'
[ng] ERROR in ./node_modules/ngx2048/node_modules/@angular/core/esm2015/core.js
[ng] Module not found: Error: Can't resolve 'rxjs/operator/share' in 'C:\Users\JB\Dropbox\dev\battle2048\node_modules\ngx2048\node_modules\@angular\core\esm2015'
所以这看起来像是某种冲突?我是否也必须分叉旧模块才能将其迁移到angular 8?您必须检查
如果你从5到8的角度看,你可以看到
更新后的步骤
对于通过路由器延迟加载的模块,不推荐通过字符串导入<代码>ng更新将自动处理此问题。新语法利用了对导入的全生态系统支持,而不是我们的自定义重写。您的loadChildren路由配置应该从字符串(如loadChildren:'./admin/admin.module#AdminModule'
更改为导入语句,如
loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule).
以及:
使用RxJS tslint自动更新规则删除不推荐的RxJS 6功能
对于大多数应用程序,这意味着运行以下两个命令:
npm install -g rxjs-tslint
rxjs-5-to-6-migrate -p src/tsconfig.app.json
你必须检查一下
如果你从5到8的角度看,你可以看到
更新后的步骤
对于通过路由器延迟加载的模块,不推荐通过字符串导入<代码>ng更新将自动处理此问题。新语法利用了对导入的全生态系统支持,而不是我们的自定义重写。您的loadChildren路由配置应该从字符串(如loadChildren:'./admin/admin.module#AdminModule'
更改为导入语句,如
loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule).
以及:
使用RxJS tslint自动更新规则删除不推荐的RxJS 6功能
对于大多数应用程序,这意味着运行以下两个命令:
npm install -g rxjs-tslint
rxjs-5-to-6-migrate -p src/tsconfig.app.json
在angular 6中,rxjs被添加到angular框架中,因此现在您无需安装该库
您需要更改导入的所有引用以使用:
import { Observable, of} from 'rxjs';
之后,任何操作函数(如map、take、mergeMap等)都应添加到此导入中,并且您需要使用。pipe(函数、函数、函数)tu使用任何类型的操作函数
import { take, map } from 'rxjs/operators';
例如:
of(inpututval).pipe(
map(res=> res//todo something with the value),
take(1)
).subscribe(res => {console.log(res)});
现在不需要对Observable的静态引用,因此您可以直接使用上一示例中
的函数I。在angular 6+rxjs中添加到angular框架中,因此现在您不需要安装库
您需要更改导入的所有引用以使用:
import { Observable, of} from 'rxjs';
之后,任何操作函数(如map、take、mergeMap等)都应添加到此导入中,并且您需要使用。pipe(函数、函数、函数)tu使用任何类型的操作函数
import { take, map } from 'rxjs/operators';
例如:
of(inpututval).pipe(
map(res=> res//todo something with the value),
take(1)
).subscribe(res => {console.log(res)});
现在不需要对Observable进行静态引用,因此您可以直接使用上一示例中
的函数I。您需要更新此特定模块中的rxjs运算符。。阅读rxjs 5到rxjs 6的迁移文档,您需要更新此特定模块中的rxjs运算符。。阅读rxjs 5到rxjs 6的迁移文档,如果您同时需要快速和肮脏的东西,对于rxjs的东西,您可以将rxjs compat
包添加到项目中。但是是的,它又快又脏^^如果您同时需要一些又快又脏的东西,对于RxJS的东西,您可以将RxJS compat
包添加到项目中。但是是的,它又快又脏^^