1.使用Cli 命令ionic generate component testHello
注意:
ionic对component
,page
等敏感 ,所以命名最好不要含有这些
自动生成了如下文件和代码
注意,新建
component
时会自动在app.module.ts
里导入,请手动删除
2.使用
在需要使用页面的module.ts里导入此component ,比如:
在html里:
<test-hello></test-hello>
还有一种写法,亲测有效
就是模仿我的另一篇博客pipe的写法,新建一个components.module.ts
,所有component共用一个这个module.ts,
然后同样在需要使用的页面的
module.ts
导入ComponentsModule