在Ionic 2中,如何创建使用Ionic组件的自定义指令?

聪明

创建基本指令很简单:

import {Component} from 'angular2/core';

@Component({
    selector: 'my-component',
    template: '<div>Hello!</div>'
})
export class MyComponent {
    constructor() {

    }
}

这按预期工作。但是,如果我想在指令中使用Ionic组件,那就麻烦了。

import {Component} from 'angular2/core';

@Component({
    selector: 'my-component',
    template: '<ion-list><ion-item>I am an item</ion-item></ion-list>'
})
export class MyComponent {
    constructor() {

    }
}

指令已呈现,但离子组件未进行转换,因此外观/工作正常。

我找不到任何例子。我应该怎么做?

聪明

这里找到答案

您必须导入Ionic组件并将其注册为“指令”

所以我的第二个例子变成:

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() {

    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章