In Ionic 2, how do I create a custom directive that uses Ionic components?

前端 未结 1 633
故里飘歌
故里飘歌 2021-02-19 21:58

Creating a basic directive is simple:

import {Component} from \'angular2/core\';

@Component({
    selector: \'my-component\',
    template: \'
Hello!&
相关标签:
1条回答
  • 2021-02-19 22:39

    Found the answer here:

    You have to import the Ionic components and register them as 'directives'

    So my second example becomes:

    import {Component} from 'angular2/core';
    import {List, Item} from 'ionic/ionic';
    
    @Component({
        selector: 'my-component',
        directives: [List, Item],
        template: '<ion-list><ion-item>I am an item</ion-item></ion-list>'
    })
    export class MyComponent {
        constructor() {
    
        }
    }
    
    0 讨论(0)
提交回复
热议问题