Inject Service In Extendable Class Typescript

520 Views Asked by At

I am aware of DI injection pattern in angular but now I am implementing Nebular so the class needs to be extend , hence unable to use constructor in this case (given that have never worked with super calls)

enter image description here

The issue is

this.authenticationService

is null despite of adding in provider.

Please help me solve this or let me know how to inject service in this case without a constructor.

2

There are 2 best solutions below

0
On

you have to inject all the params in child constructor again call super() with params as follows.

export class ChildComponent extends ParentComponent {

   constructor(prentDepService1:any,prentDepService2:any)
   {
     super(prentDepService1,prentDepService2);
   }
}
1
On

Update your constructor to:

export class NgxLoginCustomComponent extends NbLoginComponent {
    constructor(
        nbAuthservice: NbAuthService,
        @Inject(NB_AUTH_OPTIONS) options = {},
        cd: ChangeDetectionRef,
        router: Router,
        authService: AuthenticationService
    ) {
        super(nbAuthservice, options, cd, router, authService);
    }
}

Refer this issue in Nebular's repository.