I would like to inject different Service depending on URL parameter.
@Injectable({
providedIn: 'root'
})
export class SomeService {
:
}
@Injectable({
providedIn: 'root'
})
export class AService extends SomeService {
:
}
@Injectable({
providedIn: 'root'
})
export class BService extends SomeService {
:
}
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.scss']
})
export class TestComponent implements OnInit {
private param = this.activatedRoute.snapshot.queryParams.someParam === 'someValue';
constructor(
private activatedRoute: ActivatedRoute,
private someService: SomeService, // when param is true, use AService. when false, use BService.
) { }
ngOnInit(): void {
}
}
When called this component with URL parameter someParam=someValue, I would like to use AService. Otherwise I would like to use BService.
How Can I do this?