Skip to content

DatePicker not updating ngModel value #10890

@sarbull

Description

@sarbull

Bug?

I have this Date Picker example

<mat-form-field>
  <input matInput [(ngModel)]="from" [matDatepicker]="from" (change)="onChangeEvent($event)" placeholder="From">

  <mat-datepicker-toggle matSuffix [for]="from"></mat-datepicker-toggle>
  <mat-datepicker #from></mat-datepicker>
</mat-form-field>
import {Component} from '@angular/core';

@Component({
  selector: 'date-filter',
  templateUrl: 'date.filter.html',
})
export class DateFilter {
  from: any;

  onChangeEvent(e): void {
    console.log(e.target.value);
    console.log('this.from = ', this.from);
  }
}

What is the expected behavior?

On date change i should have the value in this.form.

What is the current behavior?

It doesn't update the model and i get this error: Uncaught Error: Cannot assign to a reference or variable!.

Metadata

Metadata

Assignees

No one assigned

    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