]>
Commit | Line | Data |
---|---|---|
4f926722 C |
1 | import { Component, forwardRef, Input } from '@angular/core' |
2 | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms' | |
3 | ||
4 | @Component({ | |
5 | selector: 'my-input-switch', | |
6 | styleUrls: [ './input-switch.component.scss' ], | |
7 | templateUrl: './input-switch.component.html', | |
8 | providers: [ | |
9 | { | |
10 | provide: NG_VALUE_ACCESSOR, | |
11 | useExisting: forwardRef(() => InputSwitchComponent), | |
12 | multi: true | |
13 | } | |
14 | ] | |
15 | }) | |
16 | export class InputSwitchComponent implements ControlValueAccessor { | |
17 | @Input() checked = false | |
18 | @Input() inputName: string | |
19 | ||
20 | propagateChange = (_: any) => { /* empty */ } | |
21 | ||
22 | writeValue (checked: boolean) { | |
f9735a9e | 23 | console.log(checked) |
4f926722 C |
24 | this.checked = checked |
25 | } | |
26 | ||
27 | registerOnChange (fn: (_: any) => void) { | |
28 | this.propagateChange = fn | |
29 | } | |
30 | ||
31 | registerOnTouched () { | |
32 | // Unused | |
33 | } | |
34 | ||
35 | update () { | |
f9735a9e | 36 | console.log(this.checked) |
4f926722 C |
37 | this.checked = !this.checked |
38 | this.propagateChange(this.checked) | |
39 | } | |
40 | } |