我有一个自定义开关,需要用于有和没有形式.
即
即
定制switch.component.html
<div class="custom-switch" [formGroup]="parentGroup"> <input id="{{ id }}" name="status" type="checkBox" [checked]="checked" formControlName="{{ switchName }}" (change)="onChange($event,id)" /> <label for="{{ id }}" class="label-default" data-toggle="tooltip" data-selector="true" data-title="Switch"></label> </div>
定制switch.component.ts
import { Component,Input } from "@angular/core"; @Component({ selector : 'custom-switch',template : 'custom-switch.component.html' }) export class CustomSwitchComponent { @Input('id') id : any = 'switch'; @Input('parentGroup') parentGroup : any; @Input('switchName') switchName : any; onChange() { //do something } }
从父组件我调用表单子组件的组件为:
<custom-switch [parentGroup]="form" [switchName]="'switch'"></custom-switch>
我想用:
<custom-switch></custom-switch>
并删除
[formGroup] =“parentGroup”和
formControlName =“{{switchName}}”
对于非形式子组件.