简体   繁体   English

如何在 window.open 和 url 中使用 angular 管道?

[英]How to use angular pipes in window.open with url?

<div class="member-img" onclick="window.open(childEpisode.File_URL | fullPath)">
</div>

the fullPath is a pipe that concatenates the domain part to the URL ie file_URL which is relative. fullPath是一个 pipe ,它将域部分连接到file_URL即相对的 file_URL。

but it doesn't work and shows nothing.但它不起作用并且什么也没有显示。

If I use it with img enter code here then it works but i want it the way I have posted above.如果我将它与 img enter code here一起使用,那么它可以工作,但我想要我上面发布的方式。

working example:工作示例:

 <img [src]="childEpisode.File_URL | fullPath" [alt]="childEpisode.Name_AR" class="member-thumnail img-fluid">

you can implement it like this:你可以像这样实现它:

<div class="member-img" (click)="openMyLink(childEpisode.File_URL | fullPath)">

then in YourComponent.ts file implement the method like this:然后在YourComponent.ts文件中实现如下方法:

openMyLink(link:string){
  window.open(link)
}

Solution:解决方案:

In html template use Angular Event binding:在 html 模板中使用 Angular 事件绑定:

<div class="member-img" (click)="openURL(childEpisode.File_URL)">...</div>

In the Component ts file inject the FullPathPipe class and use it's transform method:在组件 ts 文件中注入FullPathPipe class 并使用它的transform方法:

constructor(private fullPathPipe: FullPathPipe) {...}

openURL(url: string) {
  const transformedURL = this.fullPathPipe.transform(url);
  window.open(transformedURL);
}

Note:笔记:

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

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