3

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

2 Answers 2

7

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>
Sign up to request clarification or add additional context in comments.

7 Comments

"addToVisibility(type,$event.target.value)" in this function first argument 'type' is the string, it can be 'company' , 'user' etc. but I try to do like this "addToVisibility('type',type)" and get undefined value.
addToVisibility(type: string, query?: any) { console.log(query); switch (type) { case 'type': { ...
what do you mean
I mean when I pass without single quote i get undefined)
check the updated answer. reference stackoverflow.com/questions/44550964/…
|
3
<select   [(ngModel)] ="selectedType" (ngModelChange)="onSelectChange($event,selectedType)">
    <option>Slect Light Dimmer</option>
<option  [ngValue]="leddim" *ngFor="let leddim of dimmerlightlist">{{leddim.NODE_NAME}} </option>

1 Comment

Please add explanation to your answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.