angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.37k stars 6.75k forks source link

bug(dateRangePicker): model set value called multiple times on init #19186

Closed mcalmus closed 4 years ago

mcalmus commented 4 years ago

Reproduction

Use StackBlitz to reproduce your issue: https://stackblitz.com/fork/components-issue

This is related to the pre-release date range picker

html:

TypeScript: private _to: Date; private _from: Date; set toDate(newDate: Date) { console.log("set to date"); this._to = newDate; } get toDate(): Date { return this._to; } ...etc.

Steps to reproduce:

  1. Create range picker attaching models to the start and end date (partial code included)
  2. Load page

Expected Behavior

What behavior were you expecting to see?

setters called once (maybe twice) during startup

Actual Behavior

What behavior did you actually see?

Set is called dozens (maybe hundreds?) of times.

Environment

crisbeto commented 4 years ago

I'm only seeing the setters being run twice with the provided code running against the latest date-range branch version. Are you sure that you weren't looking at the getters?

mcalmus commented 4 years ago

Turns out my get method was doing something like: return new Date(this._to); so there was a new object every time.

angular-automatic-lock-bot[bot] commented 4 years ago

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.