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

标签 javascript ionic2

创建基本指令很简单:

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 组件未转换,因此无法正常显示/工作。

我找不到这方面的任何例子。我应该怎么做?

最佳答案

找到答案 here :

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

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

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

    }
}

关于javascript - 在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34976283/

相关文章:

javascript - css不影响div

javascript - 从侧 View 到选项卡 View 的 ionic /Angular 切换

javascript - Ionic dom-to-image 插件在渲染时崩溃

javascript - 如何将 graphQL 查询转换为 React 组件?

javascript - JS事件循环混淆

javascript - 如何在链接下方添加高亮的高亮条?

ionic2 - hideBackButton 属性也隐藏了 menuToggle 按钮

javascript - 如何在 express + passport js 中删除注销时的 cookie?

angular - 背景地理定位 ionic 3 不更新

http - curl POST 有效,但 ionic this.http.post 无效