2017-04-18 4 views
1

In Ionic 2, how do I create a custom directive that uses Ionic components?Ionic 2バージョン3.0.1では、Ionicコンポーネントを使用するカスタムコンポーネントを作成するにはどうすればよいですか?

この回答はもう機能しません。

import {IONIC_DIRECTIVES} from 'ionic-angular' 

これも機能しません。 Ionic 2、バージョン3.0.1でIonicコンポーネントを使用するカスタムコンポーネントを作成するにはどうすればよいですか?

+0

私は同様の問題に直面しています。あなたは運がありましたか? –

+0

私は 'ionic-angular 'から' import {IonicModule}'をインポートして、このモジュールをカスタムコンポーネントモジュールのインポートセクションに追加することで動作させることができました。それが正しいかどうかは分かりませんが、正しく動作します。 –

答えて

1

あなたが遅延ロードを使用した後、この問題で立ち往生している場合は、そのようにすることを行う必要があります。

  1. CustomComponentModule
  2. カスタムコンポーネントのテンプレートで
  3. 利用イオン成分
  4. の「輸入」パラメータにIonicModuleを追加そのコンポーネント(CustomComponentModule)を使用するAnotherComponentModuleの 'imports'パラメータにCustomComponentModuleを追加します。私のために働くのです

deletable.module.ts

import { NgModule } from '@angular/core'; 
import { DeletableItem } from './deletable'; 
import { IonicModule } from 'ionic-angular'; 

@NgModule({ 
    declarations: [ 
    DeletableItem 
    ], 
    imports: [ 
    IonicModule 
    ], 
    exports: [ 
    DeletableItem 
    ] 
}) 
export class DeletableModule {} 

bill.html

<ion-content padding> 
    <ion-list> 
    <ion-item *ngFor="let bill of bills" (click)="openEdit(bill)"> 
     <ion-label text-left>{{bill.name}}</ion-label> 
     <ion-label text-right>{{bill.amount}}</ion-label> 
     <deletableItem></deletableItem> 
    </ion-item> 
    </ion-list> 
</ion-content> 

bill.module.ts

import { NgModule } from '@angular/core'; 
import { IonicPageModule } from 'ionic-angular'; 
import { BillPage } from './bill'; 

import { DeletableModule } from './../../components/deletable/deletable.module' 

@NgModule({ 
    declarations: [ 
    BillPage 
    ], 
    imports: [ 
    IonicPageModule.forChild(BillPage), 
    DeletableModule 
    ], 
    exports: [ 
    BillPage 
    ] 
}) 
export class BillModule {} 

関連する問題