Can't set default value for mdb-select


Topic: Can't set default value for mdb-select

Chen asked 7 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


Damian Gemza staff commented 7 years ago

In your html code, please change ngModel value from selectedCharacter to selectedValue. And it will work. Best Regards, Damian

Chen commented 7 years ago

still hasn't solved my problem

Damian Gemza staff commented 7 years ago

Did you imported FormsModule in your app.module.ts file? It's needed in this case.

Chen commented 7 years ago

I DID import it, didn't help

Damian Gemza staff commented 7 years ago

Chen for me, your code is working when I changed selectedCharacter to selectedValue. Does your console throws you any errors?

Chen commented 7 years ago

Nope no errors, and like I said I'm using MDB 5.2.3, and Angular 5.1.2

Damian Gemza staff commented 7 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 commented 7 years ago

Never mind, fixed it, didn't have a name attribute, didn't see the warning i guess

luis.rodas commented 4 years ago

Chen, can you post the solution please.


Arkadiusz Idzikowski staff commented 4 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)?


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: Free
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: Yes
  • Provided link: No