Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How pass objects to function in select? Angular 4

Tags:

angular

I need to pass object to the function when I change option in select.

<select (change)="addToVisibility('type',$event.target.value)">
     <option *ngFor="let type of selectedTypes" [ngValue]="type">
            {{type.title}}
     </option>
</select>

I try like this, but always in function pass type.title, but i need to pass type. Please help me) P.S. Sorry for my bad English

like image 296
Belouccio Avatar asked May 23 '26 21:05

Belouccio


2 Answers

You can use ngModel with ngModelChange as follows

<select [(ngModel)] ="selectedType" (ngModelChange)="addToVisibility(selectedType,$event.target.value)">
     <option *ngFor="let type of selectedTypes" [ngValue]="type">
            {{type.title}}
     </option>
</select>
like image 168
Sajeetharan Avatar answered May 26 '26 10:05

Sajeetharan


<select   [(ngModel)] ="selectedType" (ngModelChange)="onSelectChange($event,selectedType)">
    <option>Slect Light Dimmer</option>
<option  [ngValue]="leddim" *ngFor="let leddim of dimmerlightlist">{{leddim.NODE_NAME}} </option>
like image 41
Nitesh Jha Avatar answered May 26 '26 11:05

Nitesh Jha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!