question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DatePicker not updating ngModel value

See original GitHub issue

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!.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
dhrncommented, Apr 17, 2018

please use (dateChange)="onValueChange($event) instead of change

0reactions
angular-automatic-lock-bot[bot]commented, Sep 8, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Datepicker does not update ng-model - Stack Overflow
Try creating a variable 'date' in your service and update the variable when the user changes the date. Then, replace {{dt}} with {{date}}...
Read more >
date-picker ngModel not work and solution I found
I want use [(ngModel)] to two way binding data, but it is not work. I check the date picker's ts file, found the...
Read more >
Datepicker in Angular using mat-datepicker | Material Design
To implement date picker in Angular we can use angular material ... I have created a date variable and bind it to datepicker...
Read more >
Datepicker - Angular Material
The datepicker allows users to enter a date either through text input, ... Notice that the emitted value does not affect the current...
Read more >
Datepicker selected value - StackBlitz
<mat-datepicker #picker1></mat-datepicker>. </mat-form-field>. <mat-form-field>. <input matInput [matDatepicker]="picker2". placeholder="Angular forms (w/.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found