I have a dropdown that contains a few options coming from a loop,I need to get the selected option(not value) on click of a button. I tried with ngModel
but I was able to get the value, not option. Can anyone please help me? Here is the code below
app.component.html
<div>
<select>
<option *ngFor="let group of groups" value="{{group.id}}">{{group.name}}</option>
</select>
</div>
<input type="button" (click)="getVal()" value="submit"/>
app.component.ts
import { Component, ViewChild, ElementRef } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
ngOnInit() {
}
getVal() {
}
groups = [{
"id": 1,
"name": "pencils",
"items": "red pencil"
},
{
"id": 2,
"name": "rubbers",
"items": "big rubber"
},
{
"id": 3,
"name": "rubbers1",
"items": "big rubber1"
}];
}