Comments (5)
It seems like a bug in the migration script. Please share one example code so we can investigate. And yes, you must add the decorator anywhere you use untilDestroyed
.
from until-destroy.
I can't seem to get it to work with Angular 9.
Example:
class Tab implements OnInit, OnDestroy {
constructor() { }
ngOnInit() {
interval(5000)
.pipe(untilDestroyed(this))
.subscribe(() => { console.log('ping from Tab...'); });
}
ngOnDestroy() {
console.log(`Tab.ngOnDestroy`);
}
}
@UntilDestroy()
@Component({ ... })
export class FirstTab extends Tab implements OnInit, OnDestroy {
constructor() { }
ngOnInit() {
super.ngOnInit();
interval(5000)
.pipe(untilDestroyed(this))
.subscribe(() => { console.log('ping from FirstTab...'); });
}
ngOnDestroy() {
super.ngOnDestroy();
console.log(`FirstTab.ngOnDestroy`);
}
}
@UntilDestroy()
@Component({ ... })
export class SecondTab extends Tab implements OnInit, OnDestroy {
constructor() { }
ngOnInit() {
super.ngOnInit();
interval(5000)
.pipe(untilDestroyed(this))
.subscribe(() => { console.log('ping from SecondTab...'); });
}
ngOnDestroy() {
super.ngOnDestroy();
console.log(`SecondTab.ngOnDestroy`);
}
}
// Included in FirstTab
@UntilDestroy()
@Component({ ... })
export class Widget implements OnInit, OnDestroy {
constructor() {
}
ngOnInit() {
super.ngOnInit();
interval(5000)
.pipe(untilDestroyed(this))
.subscribe(() => { console.log('ping from Widget...'); });
}
ngOnDestroy() {
super.ngOnDestroy();
console.log(`Widget.ngOnDestroy`);
}
}
When I bounce back and forth between tabs, I see the '{name}.ngOnDestroy' statements for all classes. However, only the interval for the Widget is cleaned up. The intervals for the Tabs are never cleared. Instead, new ones are created. If I bounce back and forth a few times times, I end up with 10+ ping statements.
I didn't have any problems before switching to Angular 9 and '@ngneat/until-destroy' (from 8 and 'ngx-take-until-destroy').
I tried adding @UntilDestroy()
to the base Tab class, but I get this error:
Uncaught TypeError: Cannot read property 'onDestroy' of undefined
at decorateDirective (:96852:45)
Any ideas what I'm doing wrong?
Does untilDestroyed no longer support classes / components that use inheritance?
Edit:
I tried moving all the logic from my base Tab class into my actual tab and removing the 'extends Tab'. Sure enough, my observables started getting cleaned up.
from until-destroy.
Okay, looks like someone else already fixed this in a different branch:
typescriptguru@b55b735
Any idea when this change will make it into the npm module?
from until-destroy.
You're welcome to submit a PR
from until-destroy.
Regarding the migration, it works only on Component/Directives. In your case, it's a simple class.
from until-destroy.
Related Issues (20)
- unsubscribed checker breaks change detection HOT 1
- Add a util cancel Promises
- Angular 14 ut could not run correctly HOT 1
- Angular 14 ut could not run correctly with a minimal reproducible example
- Angular 14 ut could not run correctly with a a minimal reproducible example HOT 7
- Can I ask what's the utility for this package?
- How to use until-destroy-migration? HOT 4
- NG0204: Token InjectionToken X is missing a ɵprov definition after Angular 15 upgrade HOT 20
- Angular 15 Directive Composition API: Cannot access [component] before initialization. HOT 4
- [Documentation] For using `untilDestroyed` in non Angular apps HOT 1
- untilDestroyed assumes ngDevMode is defined HOT 2
- Warnings for github actions builds
- Component is undefined if @UntilDestroy() is used HOT 2
- Supporting other types of Subscriptions HOT 1
- Support TS 5.0 non experimental decorators for the UntilDestroy decorator
- ERROR Error: ASSERTION ERROR: token must be defined [Expected=> null != undefined <=Actual] HOT 5
- Angular 16 takeUntilDestroyed HOT 7
- Need upgrade for Angular 17 HOT 2
- Debugger in source code
- Error when using Target 2022 - Similar issue link provided HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from until-destroy.