Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
125
rated 0 times [  130] [ 5]  / answers: 1 / hits: 18800  / 7 Years ago, tue, november 21, 2017, 12:00:00
<tr (click)=onRowClick(myDropDownList.value)>
<td>
<select #myDropDownList (click)=$event.stopPropagation() (change)=onChange($event.target.value)>
<option *ngFor=let n of numbers [value]=n>{{n}}</option>
</select>
</td>
</tr>


I was trying to get selected value from the drop down list and assign it to the onRowClick function. But myDropDownList always appears to be undefined for some reason. I was wondering what might go wrong here.


More From » html

 Answers
13

I actually ended up with using ElementRef as the solution, which in my opinion is probably simpler and more straightforward.



@ViewChild('myDropDownList') myDropDownList: ElementRef;

onRowClick(){
const selectedValue = this.myDropDownList.nativeElement.value;
//...
}


Using forms was just a bit overkill in my case. But thanks for putting it out as another possible alternative.


[#55879] Friday, November 17, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brooksb

Total Points: 480
Total Questions: 98
Total Answers: 106

Location: Somalia
Member since Mon, Feb 27, 2023
1 Year ago
;