angular: Angular Router does not destroy component if an error was thrown
I’m submitting a…
[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report <!-- Please search GitHub for a similar issue or PR before submitting -->
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
If component 1 throws an error, and then a user navigates to component 2, the error in component 1 will prevent component 1 from being destroyed by the router.
Expected behavior
Components should be destroyed by the angular router whether they throw an error or not.
Minimal reproduction of the problem with instructions
- Notice error on Developer console on
Login
Component - Click login button using
diagnosebug
for the username and no password. - Scroll down page.
- See that
Login
component is still visible beneathDashboard
component - Click Logout button.
- Scroll up and notice another duplicate copy of
Login
component, andDashboard
component still visible. - Can be repeated to infinite resulting in more duplicate components never being destroyed.
Environment
Angular version: 4.3.6
Browser:
- [x ] Chrome (desktop) version 63
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
For Tooling issues:
- Node version: XX
- Platform:
Others:
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 11
- Comments: 21 (1 by maintainers)
Attached you can find a simple sample application which reproduces the problem.
The setup was done using angular-cli as follows:
I added the
BrowserAnimationsModule
and theReactiveFormsModule
in theapp.module.ts
file and I updated the routing to include two routes to each component.The
app.component.html
file was altered as follows:Component “One” was left as-is, component “Two” was changed to include the following HTML:
The form group does not exists. When using
ng serve
orng build
to run the application, when clicking on the link to component “Two” it will crash and the content will be appended to the div.Note that running
ng build --prod
will throw an error saying that “Property ‘formGroup’ does not exist on type ‘ExampleTwoComponent’.”, so a production build is covered.issue-19273.zip
Same problem here!
Same problem here I am using BrowserAnimations module in my project . These links might help identifying more about problem .
https://stackoverflow.com/questions/45622453/angular2-router-appends-component-instead-of-replacing-it?rq=1
https://stackoverflow.com/questions/45762690/angular-4-router-is-appending-components-on-routerlink-navigation-instead-of-des
I am also seeing this issue, i have tried to create a reproducable stackblitz but i havent been able to recreate the issue…
So if any of you can recreate the bug in a very very simple plunkr app then i’m sure it will be helpful for the angular team 😃
23 days goes by, can anyone from angular take a look at this? Or give an estimate of when they could?
So this is a duplicate of an older bug issued here #19093 But I think someone of Angular team just looked at it a week ago
I also have same error but can’t get rid of BrowserAnimationModule (cause whole app is based on angular material components… ). I really think this happen only when there is an error thrown by Angular due to a DOM problem (something wrong in {{ }} templating or in a custom directive). I couldn’t reproduce it in another case.
I really hope Angular team could have a look on it soon, as soon as they release Angular 5
I had a similar issue in my app, and removing the
BrowserAnimationModule
from theapp.modules.ts
file fixed the problem, as mentioned before.It turned out the issue was because the second component was throwing an error. When we resolved the error in the second component the appended routing issue was resolved.
Anybody there?