我坚持将自定义组件导入Ionic 3中的页面.这在Ionic 2中相对微不足道,但我似乎无法在Ionic 3中使用它.
我有一个名为other的现有页面模块.运行离子g组件测试后,我将自动生成的ComponentsModule导入other.module.ts并将其添加到imports数组中.
import { ComponentsModule } from "../../components/components.module"; @NgModule({ declarations: [ OtherPage,],imports: [ IonicPageModule.forChild(OtherPage),ComponentsModule,}) export class OtherPageModule {}
然后,我将组件选择器添加到页面中< test>< / test>.
这会导致错误:
polyfills.js:3 Unhandled Promise rejection: Template parse errors: 'test' is not a known element: 1. If 'test' is an Angular component,then verify that it is part of this module. 2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. (" <ion-content padding> [ERROR ->]<test> </test> </ion-content> "): ng:///AppModule/OtherPage.html@16:0 ; Zone: <root> ; Task: Promise.then ; Value: Error: Template parse errors: 'test' is not a known element: 1. If 'test' is an Angular component,then verify that it is part of this module.
这对我不起作用.我还尝试为测试组件创建一个模块并以相同的方式导入它,但这对我不起作用.
我似乎无法找到任何文档或示例.如何在Ionic 3中导入自定义组件?
解决方法
你需要像下面这样做:
import { ComponentsModule } from "../../components/components.module"; @NgModule({ declarations: [ OtherPage,entryComponents: [ ComponentsModule ] }) export class OtherPageModule {}