如何通过在ionic2中扩展BaseInput来创建自定义表单组件

时间:2017-07-18 03:01:58

标签: ionic-framework ionic2 ionic3

我想通过扩展BaseInput在ionic2中创建自定义表单输入组件。但它没有呈现,我无法在DOM上找到它。

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 个答案:

没有答案