美文网首页ionic2
ionic3.X 自定义 component

ionic3.X 自定义 component

作者: YuRi_1 | 来源:发表于2017-06-15 15:59 被阅读2453次
    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,个人不建议使用。

    相关文章

      网友评论

        本文标题:ionic3.X 自定义 component

        本文链接:https://www.haomeiwen.com/subject/yqcuqxtx.html