javascript - How to detect changes with Date objects in Angular2? -
date objects modified using setdate method arent getting updated in template.
in template:
<p>{{date | date:'mediumdate'}}</p>
in component:
nextday(){ this.date.setdate(this.date.getdate()+1); }
but when call nextday function, template isnt updated new value.
the way change detection working doing this:
nextday(){ var tomorrow = new date(); tomorrow.setdate(this.date.getdate()+1); this.date = tomorrow; }
are there better way accomplish same task?
i think right way, change reference of date variable. docs here have:
the default change detection algorithm looks differences comparing bound-property values reference across change detection runs.
so if date reference remains same, nothing happen. need new date reference , that's why second version of nextday()
works.
if remove formatting pipe see still second version of nextday()
works.
Comments
Post a Comment