Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: problem with select option in Angular

Yo pro asked 6 years ago


How do I get the value of the selected option?

Damian Gemza staff answered 6 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

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No
Tags