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
31 selectedId: number | string
33 propagateChange = (_: any) => { /* empty */ }
35 writeValue (id: number | string) {
39 registerOnChange (fn: (_: any) => void) {
40 this.propagateChange = fn
43 registerOnTouched () {
48 this.propagateChange(this.selectedId)