angular - Hur man lagrar dropdown-val i en variabel och skriver ut det i konsolen?
Jag vill binda mitt dropdownval till en variabel och skriva ut det i konsolen. Hur kan jag göra detta?
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>
Svar #1
<select [(ngModel)]="selected" (ngModelChange)="selectedChanged()" class="form-control box" id="title" required>
class MyComponent {
selected:string;
selectedChanged() {
console.log(this.selected);
}
}
