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.

bug(MatDatePicker): change events emitted despite using emitEvents false

See original GitHub issue

Reproduction

https://stackblitz.com/edit/components-issue-xay9ty?file=src%2Fapp%2Fexample-component.ts

  1. Click the “emitEvent: false” button

Expected Behavior

valueChanges should not emit values when setting a value with emitEvent: false

This works correctly for “normal” input components, but not when attaching a date picker.

The reproduction includes a text input and a select for comparison.

Actual Behavior

Using setValue or patchValue with emitEvent set to false has the valueChanges observable emit changes.

Environment

  • Angular: 10.0.3
  • CDK/Material: 10.0.3
  • Browser: Chrome
  • Operating System: Windows

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:11
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
Brutusncommented, Oct 12, 2020

I encountered this bug aswell.

I have a formGroup (attached to a <mat-date-range-*> inside the template):

readonly myRange = new FormGroup({ start: new FormControl({ value: null, disabled: true }), end: new FormControl({ value: null, disabled: true }), });

I do listnen to the value changes, with nothing special, just to console log the value.

this.myRange.valueChanges.subscribe(console.log);

Later in my code I patch the value with emit false.

this.myRange.patchValue({ start: new Date(2020, 9, 5), end: new Date(2020, 9, 10) }, { emitEvent: false });

The value is correctly set, but I don’t expect the console.log to show anything.

Edit: added a stack blitz to show the issue: https://stackblitz.com/edit/angular-ivy-hgtnqf?file=src%2Fapp%2Fapp.component.ts

4reactions
UshakovMaksymcommented, Sep 13, 2022

The problem is in interface, we are setting emitEvent option, but FormControl component check old option name emitViewModelChange.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Material mat-datepicker (change) event and format
When I open date picker dialog and select any date, date shows up in input text box, but I want to call a...
Read more >
Issue With The Mat-Datepicker In A Loop - ADocLib
For example, if <mat-datepicker> is configured to work with javascript ... bug(MatDatePicker): change events emitted despite using emitEvents false #20218.
Read more >
UNPKG - @angular/material
_focusIndex = value;\n }\n\n /** Event emitted when the option is selected. ... 0));\n\n // If there is a change in selected index,...
Read more >
angular/angular - Gitter
<mat-form-field> <input matInput [matDatepicker]="startPicker" ... in that service which you use to emit events from the app-navbar and you ...
Read more >
Datepicker input and change events - StackBlitz
Dependencies · <mat-form-field> · <input matInput [matDatepicker]="picker" · placeholder="Input & change events" · (dateInput)="addEvent('input', · $event)" ( ...
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