import {Component, OnInit} from '@angular/core'; import {FieldType} from '@ngx-formly/material'; import {Observable} from 'rxjs'; @Component({ selector: 'jhi-select-custom', templateUrl: './select-custom.component.html', styleUrls: ['./select-custom.component.css'] }) export class SelectCustomComponent extends FieldType implements OnInit { items: any[] | Observable; searchable = false; itemSelected = null; constructor() { super(); } ngOnInit(): void { this.items = this.field.templateOptions.options; this.searchable = !!this.field.templateOptions.autocomplete; if (this.model[this.field['variable']]) { this.itemSelected = this.model[this.field['variable']]; } } setToModel(): void { if (this.itemSelected) { this.model[this.field['variable']] = this.itemSelected; this.field.formControl.setValue(this.itemSelected); } else { this.model[this.field['variable']] = null; this.field.formControl.setValue(''); } } }