]>
Commit | Line | Data |
---|---|---|
728a1236 RK |
1 | import { Component, forwardRef, Input } from '@angular/core' |
2 | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms' | |
3 | ||
4 | @Component({ | |
5 | selector: 'my-select-custom-input', | |
6 | styleUrls: [ './select-custom-input.component.scss' ], | |
7 | templateUrl: './select-custom-input.component.html', | |
8 | providers: [ | |
9 | { | |
10 | provide: NG_VALUE_ACCESSOR, | |
11 | useExisting: forwardRef(() => SelectCustomInputComponent), | |
12 | multi: true | |
13 | } | |
14 | ] | |
15 | }) | |
16 | export class SelectCustomInputComponent implements ControlValueAccessor { | |
17 | @Input() items: any[] = [] | |
18 | ||
19 | selectedId: number | |
20 | ||
21 | // ng-select options | |
22 | bindLabel = 'label' | |
23 | bindValue = 'id' | |
24 | clearable = false | |
25 | searchable = false | |
26 | ||
27 | propagateChange = (_: any) => { /* empty */ } | |
28 | ||
29 | writeValue (id: number) { | |
30 | this.selectedId = id | |
31 | } | |
32 | ||
33 | registerOnChange (fn: (_: any) => void) { | |
34 | this.propagateChange = fn | |
35 | } | |
36 | ||
37 | registerOnTouched () { | |
38 | // Unused | |
39 | } | |
40 | ||
41 | onModelChange () { | |
42 | this.propagateChange(this.selectedId) | |
43 | } | |
44 | } |