I have angular 2 project. I want to open static help files available on server in new window. I tried window.open(help/index.html).
It navigates to the page but throws error about route not found.
I have also tried to run above code outside angular zone but makes no difference.
I suspect as browser location changes angular detects it in next change detection cycle and try to route to that URL.
What could be done to achieve this.
You could try and leverage the name parameter of the window.open() method which is the equivalent of the target attribute in anchor tags.
window.open("help/index.html", "_blank");
working Plunker example
The way that I got around the error is to wrap the window.open in a timeout. This allows for the window open to run after the angular code finishes. Normally you don't want to use timeouts inside of your app but since this is opening a new window at a new location that won't use the same instance of your app it should be okay.
setTimeout(() => {
window.open("./README.md", "_blank");
});
Working Plunker
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With