Topic: Can't set default value for mdb-select
Chen free asked 6 years ago
I tried following the instructions in the documentation, but it doesn't seem to work.
What am I missing?
.html file:
<mdb-select [(ngModel)]="selectedCharacter" [options]="dateOptionsSelect" placeholder="Choose time period"></mdb-select>
.ts file :
dateOptionsSelect= [ { value: '1', label: 'Today', selected: true }, { value: '2', label: 'Yesterday' }, { value: '3', label: 'Last 7 days' }, { value: '4', label: 'Last 30 days' }, { value: '5', label: 'Last week' }, { value: '6', label: 'Last month' } ]; selectedValue = '1';
MDB-Angular 5.2.3
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: Free
- Premium support: No
- Technology: MDB Angular
- MDB Version: -
- Device: -
- Browser: -
- OS: -
- Provided sample code: Yes
- Provided link: No
Tags
Damian Gemza staff commented 6 years ago
In your html code, please change ngModel value from selectedCharacter to selectedValue. And it will work. Best Regards, DamianChen free commented 6 years ago
still hasn't solved my problemDamian Gemza staff commented 6 years ago
Did you imported FormsModule in your app.module.ts file? It's needed in this case.Chen free commented 6 years ago
I DID import it, didn't helpDamian Gemza staff commented 6 years ago
Chen for me, your code is working when I changed selectedCharacter to selectedValue. Does your console throws you any errors?Chen free commented 6 years ago
Nope no errors, and like I said I'm using MDB 5.2.3, and Angular 5.1.2Damian Gemza staff commented 6 years ago
Could you paste me your whole .html and .ts code from component.html and component.ts files? There must be something wrong.Chen free commented 6 years ago
Never mind, fixed it, didn't have a name attribute, didn't see the warning i guessluis.rodas free commented 3 years ago
Chen, can you post the solution please.
Arkadiusz Idzikowski staff commented 3 years ago
@luis.rodas could you provide more information about the problem? Which MDB Angular version do you use and which select component (we added a new version of select in v 9.3.0)?