1 import { Component, forwardRef, Input } from '@angular/core'
2 import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
4 export type SelectOptionsItem = {
13 selector: 'my-select-options',
14 styleUrls: [ './select-shared.component.scss' ],
15 templateUrl: './select-options.component.html',
18 provide: NG_VALUE_ACCESSOR,
19 useExisting: forwardRef(() => SelectOptionsComponent),
24 export class SelectOptionsComponent implements ControlValueAccessor {
25 @Input() items: SelectOptionsItem[] = []
26 @Input() clearable = false
27 @Input() searchable = false
28 @Input() groupBy: string
29 @Input() labelForId: string
30 @Input() searchFn: any
32 selectedId: number | string
34 propagateChange = (_: any) => { /* empty */ }
36 writeValue (id: number | string) {
40 registerOnChange (fn: (_: any) => void) {
41 this.propagateChange = fn
44 registerOnTouched () {
49 this.propagateChange(this.selectedId)