You need to read the selected value back in the component, do not try to parse the HTML looking for it. You are binding the value using [(selectedLevel)]
so selectedLevel
in your component has the selected value of that select.
See stackblitz
select-overview-example.html
<h4>Basic mat-select</h4>
<mat-form-field>
<mat-select placeholder="Favorite food" name="foods" [(value)]="selectedFood">
<mat-option *ngFor="let food of foods" [value]="food.value">
{{food.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
<p>Selected food = {{selectedFood}}</p>
<h4>Basic mat-select with ngModel</h4>
<mat-form-field>
<mat-select placeholder="Favorite food" name="foods2" [(ngModel)]="selectedFoodModel">
<mat-option *ngFor="let food of foods" [value]="food.value">
{{food.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
<p>Selected food = {{selectedFoodModel}}</p>
component.ts
import {Component, OnInit} from '@angular/core';
export interface Food {
value: string;
viewValue: string;
}
@Component({
selector: 'select-overview-example',
templateUrl: 'select-overview-example.html',
styleUrls: ['select-overview-example.css'],
})
export class SelectOverviewExample implements OnInit {
selectedFood: string;
selectedFoodModel: string;
foods: Food[] = [
{value: 'steak-0', viewValue: 'Steak'},
{value: 'pizza-1', viewValue: 'Pizza'},
{value: 'tacos-2', viewValue: 'Tacos'}
];
ngOnInit(){
this.selectedFood = this.foods[1].value;
this.selectedFoodModel = this.foods[1].value;
}
}
when i select one option then there is no select value in mat-select element
<= how are you selecting this? Do you mean select in the code behind (.ts file) or interacting with the control via the browser? – Igor