0

I am having a link which I tries to open in a new tab in angular. But my routing is always going to home since the route that the link creates will be always unique. What have I tried. In component.html file

<a (click) = openFile(element)/>

In .Ts file

    openFile(myFile: any){
          this.myService.getFile.subscribe((res: any) => {
          const file = new Blob([res]); 
          //file = myOutputfile.pdf
         window.open(file);
}

So, the above code actually opens a new tab, but then again redirecting to home page. First the new tab opens with localhost://myOutputfile.pdf, then immediately getting routed to localhost://home. The entire angular routing module gets called. How can I solve this.

shakz
  • 629
  • 3
  • 14
  • 38
  • 1
    Does this answer your question? [How display pdf in new tab using blob](https://stackoverflow.com/questions/49321675/how-display-pdf-in-new-tab-using-blob) – The Head Rush Nov 11 '21 at 16:49
  • can you show demo in stackblitz ? – Developer Nov 11 '21 at 16:57
  • 1
    @TheHeadRush: It almost solved my issue. Now that redirect to home is not there. I think I am trying to figure it out – shakz Nov 11 '21 at 17:01
  • @GaurangDhorda: I will create and will update you. Thanks – shakz Nov 11 '21 at 17:04
  • may be wild card routes is redirecting you to home page @shakz – Developer Nov 11 '21 at 17:06
  • Yes..Wild card routes is there. That I cannot avoid. Along with that piece of code which maps to home for **, how I can have this new tab working in tandem is what I am trying for. – shakz Nov 11 '21 at 17:14
  • Don't map your root component to `**`. That should be used to indicate a client side 404. – The Head Rush Nov 11 '21 at 17:24
  • Ok.. Is there a way to open the pdf url. For me, it is opening up a blob in the new tab. – shakz Nov 12 '21 at 17:19
  • I was able to figure this out.I have added responsetype as Httpresponse in the angular post method. This resolved the issue.Thanks all – shakz Nov 12 '21 at 18:16

0 Answers0