problem with select option in Angular


Topic: problem with select option in Angular

Yo pro asked 7 years ago

How do I get the value of the selected option?

Damian Gemza staff answered 7 years ago

Dear Yo, You're able to get value of selected item by using ngModel attribute. Just look at my code. html:
<div class="row">

<div class="col-md-6">

<mdb-select [options]="optionsSelect"placeholder="Choose your option" [(ngModel)]="value"></mdb-select>

<label>Example label</label>

<p>Select value: {{value}}</p>

</div>

</div>
ts:
value: string;

optionsSelect:Array<any>;

ngOnInit() {

this.optionsSelect= [

{ value: '1', label: 'Option 1' },

{ value: '2', label: 'Option 2' },

{ value: '3', label: 'Option 3' },

];

}
Remember to import FormsModule in your app.module to use ngModel. Best Regards, Damian
Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Resolved

Specification of the issue
  • User: Pro
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No