Ionic 3 can't use ion-* components inside my custom components

混江龙づ霸主 提交于 2019-12-03 08:14:30

问题


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.

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.

The error is:

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

What am I doing wrong?


回答1:


Alright, so I figured out the solution:

All i needed was to import IonicModule in components.module, without forRoot(..).

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




回答2:


Based on Eliran response, here you are an example in case somebody need something visual, in components.module.ts:

@NgModule({
 imports: [
  CommonModule, <<<< add the angular common module
  IonicModule <<<< add the ionic module
 ],
 ...
})


来源:https://stackoverflow.com/questions/43425090/ionic-3-cant-use-ion-components-inside-my-custom-components

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!