ionic4学习笔记(四)--自定义公共模块
在angular中,我们都是自定义组件来使用,但是ionic4之后,沿用了angular的模块化思想,使用懒加载的方式加载页面,每个页面都是一个模块,要是继续创建组件的话,不能在多个模块中引用同一组件,所以我们要把模块创建为组件,让模块来引用模块。创建一个tabs项目,在项目中执行命令ionic g module module/listionic g component module/lis...
在angular中,我们都是自定义组件来使用,但是ionic4之后,沿用了angular的模块化思想,使用懒加载的方式加载页面,每个页面都是一个模块,要是继续创建组件的话,不能在多个模块中引用同一组件,所以我们要把组件创建为模块,让模块来引用模块。
创建一个tabs项目,在项目中执行命令
ionic g module module/list
ionic g component module/list


在list.module.ts中引入ListComponent,并且将ListComponent暴露出去
在其他模块中引用

报错:
ERROR Error: Uncaught (in promise): Error: Can’t export directive ListComponent from ListModule as it was neither declared nor imported!
Error: Can’t export directive ListComponent from ListModule as it was neither declared nor imported!
at syntaxError (compiler.js:2175)
at compiler.js:19906
at Array.forEach ()
at CompileMetadataResolver.getNgModuleMetadata (compiler.js:19896)
at CompileMetadataResolver.getNgModuleSummary (compiler.js:19748)
at compiler.js:19830
at Array.forEach ()
at CompileMetadataResolver.getNgModuleMetadata (compiler.js:19808)
at JitCompiler._loadModules (compiler.js:25582)
at JitCompiler._compileModuleAndComponents (compiler.js:25565)
at resolvePromise (zone-evergreen.js:797)
at resolvePromise (zone-evergreen.js:754)
at zone-evergreen.js:858
at ZoneDelegate.invokeTask (zone-evergreen.js:391)
at Object.onInvokeTask (core.js:34182)
at ZoneDelegate.invokeTask (zone-evergreen.js:390)
at Zone.runTask (zone-evergreen.js:168)
at drainMicroTaskQueue (zone-evergreen.js:559)

解决方法:
成功!
更多推荐
所有评论(0)