加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – Ionic 3导入自定义组件

发布时间:2020-12-17 18:06:27 所属栏目:安全 来源:网络整理
导读:我坚持将自定义组件导入Ionic 3中的页面.这在Ionic 2中相对微不足道,但我似乎无法在Ionic 3中使用它. 我有一个名为other的现有页面模块.运行离子g组件测试后,我将自动生成的ComponentsModule导入other.module.ts并将其添加到imports数组中. import { Compone
我坚持将自定义组件导入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 {}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读