I'm new to Angular2 and and I have two services DefaultService
And SpecialService
that shoud be used alternatively according to a component state
I don't know if I can Inject into my component a singleton GeneralService
that somehow behave like DefaultService
or SpecialService
by changing its implementation.
I have another idea to inject both services in generalService
and delegate thier methods to the appropriate service.
thanks to tell me how can I implement the first Idea if doable, or suggest me anothers.
@Component({
selector: 'my-app',
templateUrl : './content.component.html'
})
export class AppComponent {
constructor(generalService : GenralService,injector : Injectot){}
@ViewChild(MySon)
private mySon : MySon;
state : State;
onChangeState(newState : State):void{
if(state = special)
//this.generalService = this.injector.get('SpecialService');
myson.updateplease();
}
}
Assume SpecialService
and DefaultService
extends GeneralService