Topic: Default value select angular

Dragonnblack pro asked 7 years ago


Hi, I did not find any way to set default value in component select in angular. Is there an opportunity to do it? Best regards,

Dawid Adach pro answered 7 years ago


Dear Dragonnblack, you  can simply use ngModel for that: .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';
Today will be selected. Please remember that you have to import FormsModule to use ngModel

Dragonnblack pro commented 7 years ago

Thank you, it is indeed logical to use ngModel ... I had not thought of it at all ...

Iyan Labao free commented 7 years ago

noob question, how to import FormsModule?

Dawid Adach pro commented 7 years ago

import { FormsModule } from '@angular/forms';


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