2017-07-18 6 views
0

BaseInputを拡張して、ionic2でカスタムフォーム入力コンポーネントを作成したいとします。しかしそれはレンダリングされず、私はDOM上でそれを見つけることができません。ionic2でBaseInputを拡張してカスタムフォームコンポーネントを作成する方法

import { Component, ElementRef, OnDestroy, Optional, Renderer, 
ViewEncapsulation } from "@angular/core"; 
import { Config, Form, Item } from "ionic-angular"; 
import { BaseInput } from "ionic-angular/util/base-input"; 
import { NG_VALUE_ACCESSOR } from "@angular/forms"; 

@Component({ 
    selector: 'my-checkbox', 
    template: 
    '<p>aaaaa</p>', 
    host: { 
    '[class.checkbox-disabled]': '_disabled' 
    }, 
    providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: MyCheckboxComponent, multi: true } ], 
    encapsulation: ViewEncapsulation.None, 
}) 
export class MyCheckboxComponent extends BaseInput<any> implements OnDestroy { 

    constructor(form: Form, config: Config, elementRef: ElementRef, renderer: Renderer, @Optional() item: Item) { 
    super(config, elementRef, renderer, 'my-checkbox', [], form, item, null); 
    } 

} 

コードはsrc/component/checkbox/checkbox.tsからコピーされ、少し変更されます。

答えて

0

私は同じ問題を抱えていました。私のコンポーネントが<ion-item>親要素内でレンダリングされませんでした。 item-content指示文を追加して修正しました

<ion-item> <ion-label>Label</ion-label> <my-checkbox item-content></my-checkbox> </ion-item>

関連する問題