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