Ionic 3不能在我的自定义组件中使用ion- *组件

问题描述:

我最近从Ionic 2升级到Ionic 3,我创建了 components.module.ts 文件并声明并导出了我自己的每个自定义组件,然后在每个页面模块中导入了这个单个文件我有。

I have recently upgraded to Ionic 3 from Ionic 2, and I created components.module.ts file and declared and exported each custom component I have, and then imported this single file in every page module I have.

所以现在的问题是我不能在我自己的组件中使用ion- *组件,因为我没有导入 IonicModule.forRoot(..)在我的components.module中。

So now the problem is that I can't use ion-* components inside my own components, because I did not imported the IonicModule.forRoot(..) inside my components.module.

错误是:


模板解析错误:'ion-spinner'不是已知元素......

"Template parse errors: 'ion-spinner' is not a known element ..."

我做错了什么?

好吧,我找到了解决方案:

Alright, so I figured out the solution:

我只需要在 components.module 中导入 IonicModule forRoot(..)

另请注意Angular的 CommonModule 也是制作Angular指令的必要条件ork,所以你可能也需要导入它。

Also note that Angular's CommonModule is also necessary to make Angular's directives work, so you probably need to import it too.