Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度扩展类构造函数重载_Angular_Constructor_Httpclient - Fatal编程技术网

Angular 角度扩展类构造函数重载

Angular 角度扩展类构造函数重载,angular,constructor,httpclient,Angular,Constructor,Httpclient,我在@nebular/auth库中将以下类扩展到NbLoginComponent。我需要向HttpClient添加一个构造函数来使用http。但是无法添加构造函数,因为NbLoginComponent默认构造函数需要4个参数,而我没有。我已经添加了这些参数,但没有成功。有人能告诉我另一种不用构造函数初始化HttpClient的方法吗 下面是我的代码 导出类NgxLoginComponent扩展了NbLoginComponent{ 受保护服务:NbAuthService; 受保护的选项:{};

我在@nebular/auth库中将以下类扩展到NbLoginComponent。我需要向HttpClient添加一个构造函数来使用http。但是无法添加构造函数,因为NbLoginComponent默认构造函数需要4个参数,而我没有。我已经添加了这些参数,但没有成功。有人能告诉我另一种不用构造函数初始化HttpClient的方法吗

下面是我的代码

导出类NgxLoginComponent扩展了NbLoginComponent{
受保护服务:NbAuthService;
受保护的选项:{};
受保护cd:ChangeDetectorRef;
受保护路由器:路由器;
建造师(
服务:NbAuthService,
选项:{},
cd:ChangeDetectorRef,
路由器:路由器,,
私有http:HttpClient
) {
超级(服务、选项、cd、路由器);
}

}
我没有使用下面使用的构造函数,它解决了我的问题

http=newhttpclient(
新的HttpXhrBackend({build:()=>new-XMLHttpRequest()})
);您应该使用@Inject(NB_AUTH_OPTIONS)受保护的选项,而不是选项:{},例如:

export class NgxLoginComponent extends NbLoginComponent {
  protected service: NbAuthService;
  protected options: {};
  protected cd: ChangeDetectorRef;
  protected router: Router;
  constructor(
    service: NbAuthService,
    @Inject(NB_AUTH_OPTIONS) protected options,
    cd: ChangeDetectorRef,
    router: Router,
    private http: HttpClient
  ) {
    super(service, options, cd, router);
  }
  }

你能创建一个stackblitz演示来展示这个问题吗?这很有效。