Usually we use data-target=\"#myModal\" in the to open a modal. Right now I need use codes to control when to open the modal.
data-target=\"#myModal\"
For me I had to settimeout in addition to @arjun-sk solution's (link), as I was getting the error
setTimeout(() => { this.modalService.open(this.loginModal, { centered: true }) }, 100);