ionic2

ionic3.X 自定义 component

2017-06-15  本文已影响2453人  YuRi_1
1.使用Cli 命令ionic generate component testHello

注意:
ionic对component,page等敏感 ,所以命名最好不要含有这些

自动生成了如下文件和代码

注意,新建component时会自动在app.module.ts里导入,请手动删除

Paste_Image.png
2.使用

在需要使用页面的module.ts里导入此component ,比如:

Paste_Image.png

在html里:
<test-hello></test-hello>



还有一种写法,亲测有效
就是模仿我的另一篇博客pipe的写法,新建一个components.module.ts,所有component共用一个这个module.ts,

Paste_Image.png
然后同样在需要使用的页面的module.ts导入ComponentsModule Paste_Image.png
不过个人觉得这样意义不大,会加载所有的components,个人不建议使用。
上一篇下一篇

猜你喜欢

热点阅读