我通过拥有私有构造函数和返回对象实例返回对象 -
export class SingletonFactory {
private static factoryInstance = new SingletonFactory();
private constructor() {
}
public static getInstance() {
return SingletonFactory.factoryInstance;
}
}
我需要向该工厂注入依赖。我将代码更改为以下 -
@Inject('MyService')
export class SingletonFactory {
private static factoryInstance = new SingletonFactory();
private constructor(private myService : MyService) {
}
public static getInstance() {
return SingletonFactory.factoryInstance;
}
}
请建议,我如何在构造函数中注入对象创建的依赖关系?
注入您的组件。
import { Router } from '@angular/router';
import { FormBuilder, FormGroup, Validators} from '@angular/forms';
import { Location } from '@angular/common';
constructor(public location: Location,public fb:FormBuilder,public global_service:GlobalService,public router: Router) {
}