ERROR TypeError: Cannot read property ‘sort’ of undefined

When you get ERROR TypeError: Cannot read property ‘sort’ of undefined while running angular app, the main cause of this error would be array initialization in the ‘app.component.ts” file.


Open ‘app.component.ts’ file in your favorite editor and check whether the component property (array) used to list multiple items is initialized either while declaring or in the constructor.

Note, try to initialize while declaring as shown below


Initialize items via constructor

Once you make changes to your code as mentioned above, then try running your application. Hope this solves your issue.

Further Learning


Leave a Reply

Notify of