12

基本的なディレクティブの作成は簡単です:

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 コンポーネントは変換されないため、適切に表示/動作しません。

これに関する例は見つかりません。どうすればいいですか?

4

1 に答える 1

12

ここで答えを見つけました:

Ionic コンポーネントをインポートして、「ディレクティブ」として登録する必要があります。

したがって、私の2番目の例は次のようになります。

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

    }
}
于 2016-01-24T13:43:39.623 に答える