Practical Solution / Detection
The problem is pop-up blocking, which is a general javascript problem and not only angular related. A solution is to detect when pop-ups are blocked/closed and to inform the user.
I did a very rough implementation. I modified the popout.services.ts
file and added a detection to see if the window is open and/or exists.
I added the detectPopBlocker
method that is executed 2 seconds after the intial window.open
is called. Please note that the original code waiting 1 second in order to send the data to the new window instance.
Project: https://stackblitz.com/edit/portal-simple-yyyffj?file=src/app/services/popout.service.ts
openPopoutModal(data) {
const windowInstance = this.openOnce(
"assets/modal/popout.html",
"MODAL_POPOUT"
);
// Wait for window instance to be created
setTimeout(() => {
this.createCDKPortal(data, windowInstance);
}, 1000);
setTimeout(() => {
this.detectPopupBlocker(windowInstance);
}, 2000);
}
detectPopupBlocker(windowInstance) {
if (
!windowInstance ||
windowInstance.closed ||
typeof windowInstance.closed == "undefined"
) {
alert(
"This site relies on a new browser windows to diplsay data. It seems the windows has been closed." +
"Please disable any pop-up blockers or other such software for the specific site. "
);
}
}
Theory
The problem is not your code but instead it is related to ad/popup blocking.
I tried the example in a browser without ad-blocking and it worked fine.
I also tried it in a chrome browser with an Adblock extension
and saw the behavior you mention (the popup window opened and closed immediately).
It notified me that one advert was blocked.
So, as I did above, I implemented one of the simple pop-up blocker detectors (maybe even simple javascript based) in order to display a message when this happens.
There are a variety of resources that show how to do this, for example: