Fix select initialization.

This commit is contained in:
2021-08-08 00:19:48 +02:00
parent e2d9983e21
commit 6f7e435455
3 changed files with 8 additions and 1 deletions

View File

@@ -17,6 +17,7 @@
<label for="service-type">Type</label>
<app-select [options]="serviceTypes"
optionLabel="label"
[value]="application?.serviceType"
(onSelection)="onServiceTypeSelection($event)"></app-select>
</div>
<div class="form-control">

View File

@@ -50,7 +50,7 @@ export class UpdateApplicationComponent implements OnInit {
const appToUpdate = { ...this.application } as Application;
appToUpdate.name = this.form.controls.name.value;
appToUpdate.serviceName = this.form.controls.serviceName.value;
// appToUpdate.serviceType = this.form.controls.serviceType.value;
appToUpdate.serviceType = this.form.controls.serviceType.value;
appToUpdate.image = this.form.controls.image.value;
this._applicationService.update(appToUpdate)

View File

@@ -19,6 +19,7 @@ export class SelectComponent implements OnChanges {
@Input() formControl: any;
@Input() options?: any[];
@Input() optionLabel?: string;
@Input() value?: any;
@ViewChild('select', {static: true}) select?: ElementRef;
@ViewChild('selectIcon', {static: true}) selectIcon?: ElementRef;
@Output() onSelection: EventEmitter<any> = new EventEmitter();
@@ -33,6 +34,11 @@ export class SelectComponent implements OnChanges {
value: option,
label: typeof this.optionLabel === 'undefined' ? undefined : option[this.optionLabel]
} as Option));
const selectedOption = this._options.find(option => option.value === this.value || option.value?.value === this.value);
if (selectedOption) {
this.setOption(selectedOption);
}
}
}