Closed cbaskins closed 4 months ago
Wrap your tab-one
component with <ng-template matTabContent>
and it will work as expected:
<mat-tab label="Second">
<ng-template matTabContent>
<app-tab-one/>
</ng-template>
</mat-tab>
This is not a bug. The component in your example is not destroyed when switching the tabs.
Indeed it does. I kinda expected the component to be destroyed when the tab content is removed from the DOM without the ng template and directive. Maybe a documentation note? Thank you! @hakimio
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.
Is this a regression?
The previous version in which this bug was not present was
No response
Description
If you have a component in a mat-tab as content when that tab is no longer in focused the body is removed but the components onDestroy method is not called. You can observe the content is removed in the dom and https://material.angular.io/components/tabs/overview#keeping-the-tab-content-inside-the-dom-while-its-off-screen supports this notion but I was expecting a components onDestroy method to be called when removed for cleanup purposes (resizeObservers et el)
Reproduction
StackBlitz link: https://stackblitz.com/edit/stackblitz-starters-vntmid?file=src%2Fmain.ts Steps to reproduce:
Expected Behavior
Console log called indicating the onDestroy method fired.
Actual Behavior
NA
Environment
Angular CLI: 18.0.1 Node: 18.20.3 Package Manager: npm 10.2.3 OS: linux x64
Angular: 18.0.0 ... animations, cdk, common, compiler, compiler-cli, core, forms ... material, platform-browser, router
Package Version
@angular-devkit/architect 0.1800.1 @angular-devkit/build-angular 18.0.1 @angular-devkit/core 18.0.1 @angular-devkit/schematics 18.0.1 @angular/cli 18.0.1 @schematics/angular 18.0.1 rxjs 7.8.1 typescript 5.4.5 zone.js 0.14.6