I have a button that opens popup where user selects some data and add to my form.
<button type="button" class="btn btn-info btn-sm" aria-hidden="true" (click)="addData()"> Add Data</button>
addData() {
this.bsModalRef = this.modalService.show(PopupComponent,
{ initialState: { createForm: this.createForm }, ignoreBackdropClick: true, animated: true, keyboard: true, class: '' });
//some code to save below
//this.bsModalRef.content.onSave
}
The above opens a pop, user selects some data and press save.
In my popup component I have this:
ngOnInit() {
this.myService.getData().subscribe((data: any[]) => {
this.myList = data.map(a => [{ name: a.name }][0]);
},
(error: any) => {
console.log(error);
});
}
I then bind myList to my select in my popup component html All of the above works fine.
The issue is when the user clicks Add Data it, it open the popup and calls my service again.
Is it possible to avoid the multiple service calls whenever user clicks add again and again.
I tried setting the value of data returned from the api to a variable which gets assigned but on the button click its always empty.
Any input please.