I need to build a TimeZone selector in my Angular 4/5 Application. When a user changes the timezone, I expect all displayed time values on the page to update immediately.
I was planning to use:
- momentjs with timezone support using
angular2-moment
andangular-moment-timezone
. - To format the date use
amLocal
pipe, followed by other pipes. - When user selects a different time zone, I am planning to call
moment.tz.setDefault(_timezone)
With the above values from this point on gets formatted as new time zone, while currently displayed time values do not change. Angular change detection mechanism does not update displayed time values, as the input values have not changed.
I do not want to create an 'impure' pipe because of performance overheads (considering timezone change is not a frequent activity).
As fallback I can create a pipe (or use an existing one) that takes the current time zone as parameter. It actually works but I will need to pass around the current time zone value to each component and template.
I have not been able to find a way for Angular change detection to believe there is a change even when there was no change of values.
Any suggestions will be welcome.