Angular多个module公用component组件
为了加载的速度今天把很多个组件都进行了分组(懒加载)处理,然后发现了一个问题,以前公用的组件(富文本编辑器等)居然开始报错了,好尴尬。
然后开始逐步的去排查,下面直接写我的最终代码吧
第一步、创建公用组件的module
// ng g module components/editor --module=app.module
第二部、创建你的components
// ng g component components/editor
第三部、修改代码
// editor.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { EditorComponent } from './Editor.component';
@NgModule({
declarations: [EditorComponent],
imports: [
CommonModule
],
// 注意这里-这里很关键有几个写几个就ok
exports: [
EditorComponent
],
})
export class EditorModule { }
// 其他的不用修改
// http://cenggel.com
第四步、引入module
//在app.module.ts或者你想使用的地方引入
import { EditorModule } from './components/editor/editor.module';
// 然后再imports里面弄进去EditorModule
第五步,开始使用
<app-editor></app-editor>
最后:注意下
如果想要分享多个组件的话可以生成一个share module,然后再里面分享多个component就可以了哦。
0 条留言
去留言还没有留言。