我想用参数初始化服务。每个组件都有自己的服务实例。
@Injectable()
export class LoggingService {
constructor( @Inject('group') @Optional() public group?: string) {
this.group = group;
}
}
可以像这样注入组件:
@Component({
selector: 'test',
templateUrl: 'test.component.html',
providers: [
LoggingService,
{ provide: 'group', useValue: 'Anythings goes here' }
]
})
export class TestComponent implements OnInit {
constructor(private logger : LoggingService) {
}
}
以上功能对我来说很好。
我还想将LoggingService注入TimeCalculationService。我如何提供' group'来自TimeCalculationService
@Injectable()
export class TimeCalculationService {
constructor(private logger : LoggingService) {
}
}
有没有这样的
@Injectable({
providers : [
{ provide: 'group', useValue: 'Anythings goes here' }
]
})