In my application, I have a service called DrawingDataService
which contains an array of data and various tools to draw this data. To ensure that DrawingDataService
acts as a singleton across all tools, I included it in the providers list of the AppModule:
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [
DrawingDataService
],
bootstrap: [AppComponent]
})
export class AppModule { }
Next, I added an injector to one of my tools:
export class LineTool extends BaseTool {
constructor(private injector: Injector) {
super();
let drawingDataService2 = this.injector.get(DrawingDataService);
However, I encountered an issue where this.injector
was null.
I am now questioning whether creating a singleton service for storing data is considered good practice.