1 import { Component, forwardRef, Input } from '@angular/core'
2 import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
5 selector: 'my-input-switch',
6 styleUrls: [ './input-switch.component.scss' ],
7 templateUrl: './input-switch.component.html',
10 provide: NG_VALUE_ACCESSOR,
11 useExisting: forwardRef(() => InputSwitchComponent),
16 export class InputSwitchComponent implements ControlValueAccessor {
17 @Input() checked = false
18 @Input() inputName: string
20 propagateChange = (_: any) => { /* empty */ }
22 writeValue (checked: boolean) {
23 this.checked = checked
26 registerOnChange (fn: (_: any) => void) {
27 this.propagateChange = fn
30 registerOnTouched () {
35 this.checked = !this.checked
36 this.propagateChange(this.checked)