简体   繁体   English

从Angular组件中打开一个外部URL

[英]Open an external URL from within Angular Component

I have a http get call within my angular app that returns a link to a dropbox file. 我在我的角度应用程序中有一个http get调用,该调用返回指向dropbox文件的链接。

Once I receive that file I want it to be automatically opened within a new browser tab. 收到该文件后,我希望在新的浏览器选项卡中自动打开该文件。

I have tried this: 我已经试过了:

window.open(data, "_blank");

The above opens the link within my localhost like so: 上面打开了本地主机中的链接,如下所示:

http://localhost:3000/dropboxLinkHere

After doing some research I have found that you cannot external links from within angular routes. 经过研究后,我发现您无法从角度路径中进行外部链接。

Does anyone know how this could be achieved? 有谁知道这将如何实现?

I just tried window.open(dropboxLinkHere,"_blank"); 我刚试过window.open(dropboxLinkHere,“ _ blank”); and it worked for me.It has to be the complete link including http or https part. 它对我有用。它必须是完整的链接,包括http或https部分。 Could you please verify the data(response) from your get call? 您能否验证一下get呼叫中的数据(响应)? For example, "www.google.com" took me within localhost like in your question. 例如,“ www.google.com”将我带到本地主机中,就像您的问题一样。 However " http://www.google.com " and " http://google.com " worked well for me. 但是,“ http://www.google.com ”和“ http://google.com ”对我来说效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM