How do I inject things into a parent class constructor even though I have to call super() in my Angular application?

I'm working with an Angular application and I'm trying to figure something out. I have this code here:

export abstract class ListPageComponent {
  ...
  constructor(protected ngZone: NgZone) {}
  ...
}
export class UserListPageComponent extends ListPageComponent {
  ...
  constructor(protected ngZone: NgZone) {
    super(ngZone);
  }
  ...
}

The issue with this is that this creates two references to ngZone, one in the child and one in the parent. What I'm trying to do is treat ngZone like a member of the parent class that the child has access to (i.e. one reference, not two).

I'm forced to call super(ngZone) because Typescript won't let me leave it out. So I either call super(ngZone) or super(), and in neither case am I'm not injecting ngZone into the parent such that it can be shared between parent and child.

If ngZone could somehow be automatically injected into the parent, that would solve my problem, but I'm not sure how to do that. Any help is much appreciated. Thanks



Read more here: https://stackoverflow.com/questions/68458675/how-do-i-inject-things-into-a-parent-class-constructor-even-though-i-have-to-cal

Content Attribution

This content was originally published by gib65 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: