app.component.ts 和页面中的离子组件

做事

我正在努力使用 ionic 中的自定义组件。

我在 app.html 中有一个菜单,我对页面使用延迟加载。

我尝试将该组件实现到 app.html 中的菜单和某些页面中。

但是我只能在 app.html 或 pages 中实现它,而不能在两者中实现。

当我仅在 app.module.ts 中包含组件时,该组件在 app.html 中工作,但如果我在页面模板中包含该组件,则会出现以下错误:

Uncaught (in promise): Error: Template parse errors: 'fa-icon' is not a known element: 1. 如果 'fa-icon' 是一个 Angular 组件,那么验证它是这个模块的一部分。2. 如果'fa-icon' 是一个Web 组件,则将'CUSTOM_ELEMENTS_SCHEMA' 添加到该组件的'@NgModule.schemas' 以抑制此消息。

当我在 app.module.ts 和页面模块中包含组件时,我收到以下错误,因为它也包含在 app.module.ts 中:

未捕获(承诺):错误:类型 FaIconComponent 是 2 个模块声明的一部分:AppModule 和 BookingMasterPageModule!请考虑将 FaIconComponent 移至导入 AppModule 和 BookingMasterPageModule 的更高模块。您还可以创建一个新的 NgModule 来导出并包含 FaIconComponent,然后在 AppModule 和 BookingMasterPageModule 中导入该 NgModule。

所以我的问题是:如何在 app.html 和我的页面中使用该组件?

本雅明·考斯库纳

好吧,第二个错误为您提供了所需的所有信息。您需要创建一个模块,让我们调用它ComponentsModule并声明和导出该模块中的所有组件。然后你可以ComponentsModule在任何你想要的地方导入

components.module.ts

@NgModule({
    declarations: [MyComponent],
    exports: [MyComponent] // this line is important. If you forget it, other modules won't be able to use this component
})
export class ComponentsModule {}

app.module.ts

@NgModule({
    imports: [ComponentsModule]
})
export class AppModule {}

custom-page.module.ts

@NgModule({
    imports: [ComponentsModule]
})
export class CustomPageModule {}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在我的 app.component.ts 中添加 2 个组件

来自分类Dev

src/app/app.component.ts(72,69) 中的错误:错误 TS1005:“,”预期

来自分类Dev

来自 app.component.ts 的 Angular 路由

来自分类Dev

Angular2 将存储在变量中的数据从 app.component.ts(父组件)传送到其他组件

来自分类Dev

从另一个组件调用 App.component.ts 方法

来自分类Dev

Codekit 无法在 angular v5 项目中编译 main.ts 和 app.component.spec.ts

来自分类Dev

Angular ngx-editor 从其他 components.ts 文件中的 app.component.ts 外包配置

来自分类Dev

升级 app.component.ts @angular/router 和 nativescript-angular/router 的问题

来自分类Dev

找不到 ./src/app/svg.component.ts 模块中的错误:错误:无法解析“./svg.component.svg”

来自分类Dev

在 Angular 7 中获取错误 ./src/app/app.component.ts 模块未找到:错误:无法解析

来自分类Dev

使用的角度app.component.ts jQuery代码

来自分类Dev

app.component.ts 的生命周期事件

来自分类Dev

app.component.ts OnInit 被调用 11 次的正常行为?

来自分类Dev

为什么我会收到“src/app/component.service.ts(9,29) 中的错误:错误 TS2304:找不到名称‘Http’。” 在角度?

来自分类Dev

如何使用离子角将参数从component.ts传递到server.ts?

来自分类Dev

app.component.ts不在tsconfig.json定义的项目中

来自分类Dev

在 angular4 的 app.component.ts 文件中使用外部库变量

来自分类Dev

Angular 在 component.ts 中存储嵌套数组

来自分类Dev

订阅的值在 component.ts 中返回 undefined 但在 service.ts 中存在值

来自分类Dev

在 ' npm test login.component.spect.ts ' 上,它说从 'login.component.ts' 找不到模块 '@app/store/user/user.actions'

来自分类Dev

如何从 TS 文件中获取或设置离子组件的属性?

来自分类Dev

src/app/logger.ts(18,16) 中的错误:错误 TS1005:'(' 预期

来自分类Dev

在app.module.ts中声明的有角子HTML引用组件

来自分类Dev

在 app.module.ts 中添加插件时出错

来自分类Dev

添加 AngularMultiSelectModule 后 app.module.ts 中的错误

来自分类Dev

如何从.component.ts文件中* ngFor生成的输入中获取值?

来自分类Dev

我需要在 angular4 中关闭 component.ts 中的弹出消息

来自分类Dev

如何将输入的keyup值绑定到component.ts中的变量?

来自分类Dev

我正在尝试在component.ts文件中包含js代码。我这样做时出错

Related 相关文章

  1. 1

    在我的 app.component.ts 中添加 2 个组件

  2. 2

    src/app/app.component.ts(72,69) 中的错误:错误 TS1005:“,”预期

  3. 3

    来自 app.component.ts 的 Angular 路由

  4. 4

    Angular2 将存储在变量中的数据从 app.component.ts(父组件)传送到其他组件

  5. 5

    从另一个组件调用 App.component.ts 方法

  6. 6

    Codekit 无法在 angular v5 项目中编译 main.ts 和 app.component.spec.ts

  7. 7

    Angular ngx-editor 从其他 components.ts 文件中的 app.component.ts 外包配置

  8. 8

    升级 app.component.ts @angular/router 和 nativescript-angular/router 的问题

  9. 9

    找不到 ./src/app/svg.component.ts 模块中的错误:错误:无法解析“./svg.component.svg”

  10. 10

    在 Angular 7 中获取错误 ./src/app/app.component.ts 模块未找到:错误:无法解析

  11. 11

    使用的角度app.component.ts jQuery代码

  12. 12

    app.component.ts 的生命周期事件

  13. 13

    app.component.ts OnInit 被调用 11 次的正常行为?

  14. 14

    为什么我会收到“src/app/component.service.ts(9,29) 中的错误:错误 TS2304:找不到名称‘Http’。” 在角度?

  15. 15

    如何使用离子角将参数从component.ts传递到server.ts?

  16. 16

    app.component.ts不在tsconfig.json定义的项目中

  17. 17

    在 angular4 的 app.component.ts 文件中使用外部库变量

  18. 18

    Angular 在 component.ts 中存储嵌套数组

  19. 19

    订阅的值在 component.ts 中返回 undefined 但在 service.ts 中存在值

  20. 20

    在 ' npm test login.component.spect.ts ' 上,它说从 'login.component.ts' 找不到模块 '@app/store/user/user.actions'

  21. 21

    如何从 TS 文件中获取或设置离子组件的属性?

  22. 22

    src/app/logger.ts(18,16) 中的错误:错误 TS1005:'(' 预期

  23. 23

    在app.module.ts中声明的有角子HTML引用组件

  24. 24

    在 app.module.ts 中添加插件时出错

  25. 25

    添加 AngularMultiSelectModule 后 app.module.ts 中的错误

  26. 26

    如何从.component.ts文件中* ngFor生成的输入中获取值?

  27. 27

    我需要在 angular4 中关闭 component.ts 中的弹出消息

  28. 28

    如何将输入的keyup值绑定到component.ts中的变量?

  29. 29

    我正在尝试在component.ts文件中包含js代码。我这样做时出错

热门标签

归档