Skip to content

DatePicker binding with value or (ngModel)? #8171

@zijianhuang

Description

@zijianhuang

Bug or proposal:

In some places, I use

            <mat-form-field fxFlexFill>
                <input matInput [matDatepicker]="picker" placeholder="Date" [value]="buffer.timeUtc" readonly />
                <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
            </mat-form-field>
            <mat-datepicker #picker (selectedChanged)="updateTimeUtc($event)" [startAt]="now"></mat-datepicker>

Property timeUtc of the buffer object works well.

In the other place, I used:

    <mat-form-field fxFlexFill>
        <input matInput [matDatepicker]="pickerReminder" placeholder="Date" [value]="selectedDate" readonly />
        <mat-datepicker-toggle matSuffix [for]="pickerReminder"></mat-datepicker-toggle>
    </mat-form-field>
    <mat-datepicker #pickerReminder></mat-datepicker>

The selectedDate object is not working well: the picker could put a date to the input box, however, the object does not get a proper value.

Now I have:

    <mat-form-field fxFlexFill>
        <input matInput [matDatepicker]="pickerReminder" placeholder="Date" [(ngModel)]="selectedDate" readonly />
        <mat-datepicker-toggle matSuffix [for]="pickerReminder"></mat-datepicker-toggle>
    </mat-form-field>
    <mat-datepicker #pickerReminder></mat-datepicker>

The binding is working well.

I see that [value] is Material2 way of data binding with input, and [(ngModel)] is Angular2 way of binding.

What is the use-case or motivation for changing an existing behavior?

The material2 doc should had mentioned how to do data binding with DatePicker along with Input.

Current implemented usages look a bit inconsistent.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular 4.4.5, Material 2.0.0-beta.12

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions