I am new to Angular and seem to have gotten into deep water for something that seems like it should be simple. I am having a problem using a ngx-bootstrap modal dialog. I am using the ModalContentComponent pattern.
export class ModalContentComponent implements OnInit {
title: string;
constructor(public bsModalRef: BsModalRef, private myService: MyService) {}
ngOnInit() {
...
}
onSubmit(form: NgForm){
...
this.myService.sort();
this.bsModalRef.hide();
}
I have a component which opens the modal which injects one of my services and BSModalService as follows:
constructor(private myService: MyService, public modalService: BsModalService ) {}
I open the modal from this component with the following:
openModalWithComponent() {
const initialState = {
title: 'Preferences';
...
};
this.bsModalRef = this.modalService.show(ModalContentComponent,{initialState});
}
I import the ModalContentComponent and have it added to the declarations array in my app.module.ts. I also have my service identified only at this level as a provider.
import { ModalContentComponent } from '.my.component';
import { MyComponent } from '.my.component';
import { MyService } from '.my.service';
declarations: [
MyComponent,
ModalContentComponent,
],
providers: [MyService],
In order to get the modal to work I have had to add ModalContentComponent to the app.module.ts entryComponents array. Once I do that the modal comes up and everything appears to work.
entryComponents: [
ModalContentComponent
]
However, the myService service is not being treated as a Singleton. ModalContentComponent is getting its own service instance of MyService.
How do I get ModalContentComponent to use the single shared instance of myService?
I think the entryComponents inclusion is causing the issue with the additional service instance but I can't get the modal to work without it.
Any pointers welcome.