angular - 未捕获( promise ): Error: Template parse errors: 'ion-col' is not a known element

标签 angular typescript ionic3

我正在尝试在 ionic 3 中创建一个自定义组件,但我似乎不知道如何正确设置 components.module 以便我可以在我的组件中使用 ionic 组件

我像这样生成了组件

 $: ionic g component my-component

当我添加

  <ion-row>
    <ion-col>
    </ion-col>
  </ion-row

my-component.html 我得到了错误

Uncaught (in promise): Error: Template parse errors: 'ion-col' is not a known element

最佳答案

使用

ionic generate component my-component

它将在 components 文件夹下的共享模块 components.module.ts 中自动声明。

因此,如果您需要使用该组件,只需在页面模块中导入上述共享模块即可。

components.module.ts(共享)

 import { IonicPageModule } from 'ionic-angular';

 @NgModule({
    declarations:[MyComponentComponent],
    imports:[
       IonicPageModule.forChild(MyComponentComponent)  // <- Add
    ],
    exports: [MyComponentComponent]
 })

关于angular - 未捕获( promise ): Error: Template parse errors: 'ion-col' is not a known element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45716172/

相关文章:

angular - 属性 'loaded' 在类型 'HttpSentEvent' 上不存在

html - 为什么我的 Angular 应用程序不显示图像?

javascript - 当我在 javascript 中手动创建列表时,无法使用 querySelectorAll(); 获取值;

reactjs - 如何使用react-input-mask( typescript )屏蔽formic中的 Material ui输入

ionic-framework - 如何在 NavParams 中设置属性以更新 Ionic 中的 url 路径?

cordova - Ionic 3 cordova-plugin-advanced-http 主机不匹配问题

javascript - 如何测试@Input()项: any in Angular?

html - html <base> 标签的空 href 是什么意思?

typescript :类型 Data<T> = Result<T, DataError>

angular - typescript 错误在@ionic-native/geolocation 中找不到名称 'Observable'