components icon indicating copy to clipboard operation
components copied to clipboard

[select] Default value not working

Open jlno opened this issue 9 years ago • 5 comments

Bug, feature request, or proposal:

my-comp.html

<md-select placeholder="State" [(ngModel)]="myState">
   <md-option *ngFor="let state of states" [value]="state.code">{{ state.name }}</md-option>
</md-select>

my-comp.ts

class MyComp {
  myState = 'AL';
  states = [{code: 'AL', name: 'Alabama'}];
}

What is the current behavior?

No item selected.

jlno avatar Mar 14 '17 13:03 jlno

Can you replicate the issue with a Plunker? Use the template here.

willshowell avatar Mar 14 '17 14:03 willshowell

@willshowell http://plnkr.co/edit/a3KtobwPGzHY4QJPDkMB?p=preview

jlno avatar Mar 14 '17 14:03 jlno

@jlno in order to use [(ngModel)], you need to import the FormsModule into your NgModule. It looks like you instead used CUSTOM_ELEMENTS_SCHEMA to get rid of the error, and that isn't the right approach.

http://plnkr.co/edit/xNKeDyZFpyJbNkA34cAq?p=preview

willshowell avatar Mar 14 '17 14:03 willshowell

@willshowell tnx!

jlno avatar Mar 14 '17 14:03 jlno

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.