风俗
现在,我需要在该类中使用angular 2实例化的一些服务。
即
// this is not angular component/service
export default class Custom {
constructor(properties) {
}
doSomething() {
// UserService is a service that is injected into other componetns constructors, but this class is not a component.
// Here i need a ref to the singleton 'UserService' made by angular
let userService = someAngularFunction.getInstance('UserService');
userService.doIt();
}
}
// in some component.
export class MyComponent implements OnInit {
doAnotherThing() {
let c = new Custom('some generic params');
c.doSomething();
}
}
// in some n number of other components, repeat the above.
'进入
MyComponent公司
MyComponent公司
,传递给
构造函数。但是,由于MyComponent本身不使用该服务
风俗
如果不是,第二个最好的选择是什么。