-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update angular, primeng, convert to standalone, inject context #28
Conversation
@@ -65,7 +75,7 @@ export class AppMenuitemComponent implements OnInit, OnDestroy { | |||
|
|||
key: string = ""; | |||
|
|||
constructor(public layoutService: LayoutService, private cd: ChangeDetectorRef, public router: Router, private menuService: MenuService) { | |||
constructor() { | |||
this.menuSourceSubscription = this.menuService.menuSource$.subscribe(value => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need variable menuSourceSubscription to keep sub ref in order to unsub.
Angular core have new way of unsub using -> https://v16.angular.io/api/core/DestroyRef
Define variable
private destroyRef = inject(DestroyRef);
and on Observable use
.pipe(takeUntilDestroyed(this.destroyRef))
Like so:
this.menuService.menuSource$
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(value => {
Promise.resolve(null).then(() => {
if (value.routeEvent) {
this.active = (value.key === this.key || value.key.startsWith(this.key + '-'));
} else {
if (value.key !== this.key && !value.key.startsWith(this.key + '-')) {
this.active = false;
}
}
});
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do use this approach in my personal projects but because it's still dev preview I don't think it's good to put into a component library / template like this one.
@@ -65,7 +75,7 @@ export class AppMenuitemComponent implements OnInit, OnDestroy { | |||
|
|||
key: string = ""; | |||
|
|||
constructor(public layoutService: LayoutService, private cd: ChangeDetectorRef, public router: Router, private menuService: MenuService) { | |||
constructor() { | |||
this.menuSourceSubscription = this.menuService.menuSource$.subscribe(value => { | |||
Promise.resolve(null).then(() => { | |||
if (value.routeEvent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.active = (value.key === this.key || value.key.startsWith(this.key + '-')) ? true : false;
this can be simplified
(value.key === this.key || value.key.startsWith(this.key + '-'))
inject
instead of constructor injection