我有一个名为"建议"的组件,我想在两个不同的页面上呈现.因此,我根据在线资源创建了一个共享模块,并将组件添加到其中,然后我将该模块导入到我需要的两个模块中.但是,当我try 编译时,我得到了如下的错误:

rror: src/app/recommendations/recommendations.component.html:69:5 - error NG8001: 'ion-card-subtitle' is not a known element:
1. If 'ion-card-subtitle' is an Angular component, then verify that it is part of this module.
2. If 'ion-card-subtitle' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

69     <ion-card-subtitle>

这些提示如下


@NgModule({
  declarations: [
    RecommendationsComponent
  ],
  imports: [
    CommonModule,
    FormsModule,
    ReactiveFormsModule,
  ],
  exports: [
    RecommendationsComponent
  ]
})
export class SharedCompsModule { }

模数1

@NgModule({
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  imports: [
    IonicModule,
    CommonModule,
    FormsModule,
    Tab1PageRoutingModule,
    SharedCompsModule
  ],
  declarations: [
    Tab1Page,
  ]
})
export class Tab1PageModule {}

模块2


@NgModule({
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  imports: [
    IonicModule,
    CommonModule,
    FormsModule,
    Tab3PageRoutingModule,
    SharedCompsModule
  ],
  declarations: [
    Tab3Page
  ]
})
export class Tab3PageModule {}

我错过了什么?

推荐答案

我们需要确保在共享模块上声明的组件也可以访问ionic组件,我们可以通过导入/导出组件工作所需的其他模块来实现这一点!我在这里输入IonicModule

@NgModule({
  declarations: [
    RecommendationsComponent
  ],
  imports: [
    IonicModule, // <- changed here!
    CommonModule,
    FormsModule,
    ReactiveFormsModule,
  ],
  exports: [
    RecommendationsComponent
  ]
})
export class SharedCompsModule { }

Angular相关问答推荐

Angular - Bootstrap 5 Carbon不工作

angular:从模板中的可观察数组获取随机元素

Angularmaterial 中的处理mat—radio—button表单值访问器

Angular 17@在大小写时切换多个值

Angular 升级到v16和Ant设计错误:';nzComponentParams';类型';ModalOptions';中不存在

带有搜索功能的CDK-VIRTUAL-SCROLL-VIEPORT不显示该值

HttpInterceptorFn在Angular 17中被忽略

如何在ANGLING v17中使用鞋带样式组件?

以Angular 动态添加和删除组件形状元素

Angular 16独立依赖注入问题

VS代码中带Angular 17的缩进新控制流

如何捕获生命周期方法中抛出的Angular组件错误?

模块内的命名路由出口 - 路径匹配但内容未加载

带有嵌套表单数组的 Angular react式表单

如何在 Angular4 中访问组件的 nativeElement?

在 Ionic 2 中使用 NodeJS.Timer 时找不到命名空间 NodeJS

Angular2 Pipes:输出原始 HTML

Angular:ViewChild 上未定义 nativeElement

从 angular2 模板调用静态函数

如何使用 @ngrx/store 获取 State 对象的当前值?