I am building an app using angular2/Typescript, and attempting to access a service injected as a dependency. In Angular 1.x, I would have accessed this service through the controller function, and all child functions would have been able to access the same dependency. Here, I am injecting it through the constructor of my component as follows:
constructor( @Inject(JRummy) rummyGame: JRummy) {
this.currentGame = new Game();
rummyGame.startGame(this.currentGame);
}
where rummyGame is the service I am attempting to inject. This is working correctly. However, after I have accessed this service within the constructor, how do I access it in other functions? For example, I have the following click function within the component, where I want to call a method in the rummyGame service:
simulateComputer():void {
rummyGame.computerPlaySolo();
}
how does the rummyGame service get injected into this click function if it was just injected into the constructor? Do I need to create a property on the component to store the instance of that service after it has been accessed by the constructor?