1 import { Component, Input, forwardRef } from '@angular/core'
2 import { NG_VALUE_ACCESSOR, ControlValueAccessor } 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
30 selectedId: number | string
32 propagateChange = (_: any) => { /* empty */ }
34 writeValue (id: number | string) {
38 registerOnChange (fn: (_: any) => void) {
39 this.propagateChange = fn
42 registerOnTouched () {
47 this.propagateChange(this.selectedId)