DEV Community

Mitch Lamers
Mitch Lamers

Posted on

Angular crash on iOS devices toLocaleDateString()

Issue

In case you are having issues of an Angular app crashing only on iOS devices check if you are using toLocaleDateString().

In case of calling this method many times it will use up all of the javascript resources and the app will be shit down.

Solutions

If possible find a way to call the method less often. Use the onPush change detection option to control the components updates.

@Component({
  changeDetection: ChangeDetectionStrategy.OnPush,
})
Enter fullscreen mode Exit fullscreen mode

If you are using toLocaleDateString() to compare dates consider using a library that handles this more efficient like date-fns https://date-fns.org/

Top comments (0)