Angular 2 opening a static page

I have an angular 2 project. I want to open the static help files available on the server in a new window. I have tried window.open(help/index.html). It moves to the page, but gives an error that the route was not found. I also tried running the above code outside the angular zone, but it doesn't matter. I suspect that changes in the location of the angular browser detect it in the next change detection cycle and try to redirect to this URL. What can be done for this.

+3
source share
2 answers

You can try and use the namemethod parameter window.open(), which is the equivalent of the attribute targetin the tag binding.

window.open("help/index.html", "_blank");

working plunger example

+3
source

The way I ran into the error is to wrap window.openin a timeout. This allows you to open the window after the angular code completes. Usually you do not want to use timeouts inside your application, but since this opens a new window in a new place that will not use the same instance of your application, everything should be in order.

setTimeout(() => {
  window.open("./README.md", "_blank");
});

Working plunker

+1
source

All Articles