I have DrawingDataService
that contains array of my data and different tools to draw this data. I want to use DrawingDataService
like singleton in all of my tools.
I set DrawingDataService
in AppModule providers list (to make as it singleton instance):
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [
DrawingDataService
],
bootstrap: [AppComponent]
})
export class AppModule { }
Then I add injector in my tool:
export class LineTool extends BaseTool {
constructor(private injector: Injector) {
super();
let drawingDataService2 = this.injector.get(DrawingDataService);
And it says me that this.injector
is null.
Is it a good practice to make singleton service for storing data?
Try to do this in next way:
And you can use it in next way: