简体   繁体   中英

Angular ERROR TypeError: Cannot read properties of undefined (reading 'onDestroy')

I have problem. Angular is sometimes showing error ERROR TypeError: Cannot read properties of undefined (reading 'onDestroy')

I am getting this error when I am running ng serve, but if I use angular universal, then page is sometimes loading properly and sometimes it is showing same error. I found out, that this error started when I started making modularization of my app.

Angular version 13.3

I had the same issue. Try to remove the .angular directory. worked for me

This happened when I was trying to use components in an ngSwitchCase that rendered ng-templates with components in them.

The components that did not implement ngOnDestroy would give me this error.

short answer, try adding ngOndestroy to components that might be rendering on the fly?

I found out solution for this hard and not typical bug. It is happening if you don't finish your modularization, but part of code you are using as modules and part as component imports.

Components which aren't modularized and used in app.component.html different than

<router-outlet></router-outlet>

are causing this error.

for my example it was

<app-navbar></app-navbar>

What is funny? If you have this error, and you add to navbar fe <div></div> and then remove it app is starting to work normally.

What is the solution? You have to modularize all components used in app.component.html properly.

I had the same problem. in my case because I defined my model without any default values and bind it to HTML like this myModel.value . so because the myModel.value is not value, I got that error. I replaced it with myModel?.value and the error fixed

I had the same problem, which was caused by a faulty import of a module. The typescript alias contained a double slash. Similar to lib//module, and once we removed this, the app worked again.

I solved my issue with updating my A13 to A14.

We had this issue on production. Turns out the issue was in our git repository. Due to some squash commits to the master branch, it seems to have gotten messed up somehow.

Fixed it by enabling the "Clean" option with clean option "Sources" in Azure DevOps pipeline, under "get sources" at the top (Classic pipeline).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM