且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Angular抽象类HttpClient注入

更新时间:2023-01-11 10:05:53

要么删除WebA

export class WebA extends Web {

   //constructor() {
   //   super("https://www.test.com");
   //}

或重复构造函数参数,并使用super()

or repeat the constructor parameters and forward them with super()

export class WebA extends Web {

   constructor(baseURL: string, protected http: HttpClient) {
      super(baseURL, http);
   }

如果在派生类(WebA)中需要构造函数,则唯一的方法是重复并转发参数.

If you need a constructor in the derived class (WebA) the only way is to repeat the parameters and forward them.

更新

使用new Xxx()创建实例时,没有自动注入之类的功能.依赖注入仅适用于Angulars DI为您创建的实例.

There is no such thin as auto-inject when you create an instance with new Xxx(). Dependency injection works only for instances that Angulars DI creates for you.

否则,请参见上面的答案.

Otherwise see my answer above.