I iterate over an array using *ngFor to create as many cards as there are in the array.
Every card should come with a specific choice in the dropdown-menu (ng-select). And when clicking or selecting this choice a list of available options should be dynamically rendered. Each list of options is uniquely linked to a card, hence the switch-logic in my .ts-template.
modal-view.component.html
<div class="card text-center" *ngFor="let alarm of alarms">
<form name="form" (ngSubmit)="f.form.valid && onSubmit()" #f="ngForm" class="col-xl-12">
<select
class="form-control"
id="option" required
[(ngModel)]="form.option"
name="option" #option="ngModel"
(click)="getSensorDesc(alarm)"
>
<option value="" selected disabled>Seleziona Giustificativo:</option>
<option *ngFor="let option of options" [ngValue]="option.value">{{ option.text }}</option>
</select>
<button type="submit" class="btn btn-danger btn-xs mt-1 col-xl-12" [disabled]="!f.form.valid">
Referta
</button>
</form>
</div>
At first the select is filled with nothing (instead i want the disabled option with no value, just like a placeholder) but when i choose an option, that option is dispatched to all the other selects. How do i fix this issue??
modal-view.component.ts If there is any other solution for render options dynamically in the select please let me know
export class ModalViewComponent implements OnInit {
options = [
{ value: 'Falso allarme', text: 'Falso allarme' },
];
getSensorDesc(alarm: Alarm) {
switch (alarm.sensor.type) {
case 'lidardx':
this.options.splice(1, 1, { value: 'Tentativo di alzata dx', text: 'Tentativo di alzarsi dal letto dx' });
break;
case 'lidarSx':
this.options.splice(1, 1, { value: 'Tentativo di alzata sx', text: 'Tentativo di alzarsi dal letto sx' });
break;
case 'peso':
this.options.splice(1, 1, { value: 'Fuori dal letto', text: 'Fuori dal letto' });
break;
case 'rumore':
this.options.splice(1, 1, { value: 'Urla inascoltate', text: 'Urla inascoltate' });
break;
default:
break;
} }