How to detect changes with Date objects in Angular2?

后端 未结 1 825
星月不相逢
星月不相逢 2021-01-18 05:18

Date objects that are modified using setDate method arent getting updated in template.

In template:

{{date | date:\'mediumDate\'}}

相关标签:
1条回答
  • 2021-01-18 05:40

    I think that is the right way, to change the reference of the date variable. From the docs here we have:

    The default change detection algorithm looks for differences by comparing bound-property values by reference across change detection runs.

    So if the date reference remains the same, nothing will happen. You need a new Date reference and that's why the second version of nextDay() works.

    If you remove the formatting pipe you will see that still only the second version of nextDay() works.

    0 讨论(0)
提交回复
热议问题