问题描述
我知道DI injection pattern的角度,但是现在我正在实现Nebular,因此该类需要扩展,因此在这种情况下无法使用构造函数(因为从未使用过超级调用)
问题是
this.authenticationService
尽管添加了提供程序,但为null。
请帮助我解决这个问题,或者让我知道在这种情况下如何在没有构造函数的情况下注入服务。
解决方法
将构造函数更新为:
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);
}
}
在Nebular的this issue中引用repository。
,您必须将所有参数注入子构造函数中,然后再次使用参数调用super()。
export class ChildComponent extends ParentComponent {
constructor(prentDepService1:any,prentDepService2:any)
{
super(prentDepService1,prentDepService2);
}
}