ankit pachori ankit pachori - 3 months ago 9
TypeScript Question

How to store dropdown selection into variable and print it on console?

I want to bind my dropdown selection into a variable and print it in console. How can i do this?

HTML

<select class="form-control box" id="title" required>
<option *ngIf="nationality_flag">{{nationality}}</option>
<option *ngFor="let lists of default_nationality">{{lists}}</option>
</select>

Answer
<select [(ngModel)]="selected" (ngModelChange)="selectedChanged()" class="form-control box" id="title" required>
class MyComponent {
  selected:string;
  selectedChanged() {
    console.log(this.selected);
  }
}
Comments