<div class="member-img" onclick="window.open(childEpisode.File_URL | fullPath)">
</div>
這fullPath是一個將域部分連接到 URL 的管道,即file_URL相對的。
但它不起作用并且什么也沒顯示。
如果我將它與 img 一起使用,enter code here那么它可以作業,但我希望它像我上面發布的那樣。
作業示例:
<img [src]="childEpisode.File_URL | fullPath" [alt]="childEpisode.Name_AR" class="member-thumnail img-fluid">
uj5u.com熱心網友回復:
你可以像這樣實作它:
<div class="member-img" (click)="openMyLink(childEpisode.File_URL | fullPath)">
然后在YourComponent.ts檔案中實作這樣的方法:
openMyLink(link:string){
window.open(link)
}
uj5u.com熱心網友回復:
解決方案:
在 html 模板中使用 Angular 事件系結:
<div class="member-img" (click)="openURL(childEpisode.File_URL)">...</div>
在組件 ts 檔案中注入FullPathPipe類并使用它的transform方法:
constructor(private fullPathPipe: FullPathPipe) {...}
openURL(url: string) {
const transformedURL = this.fullPathPipe.transform(url);
window.open(transformedURL);
}
筆記:
- 模板陳述句中不允許使用管道運算子。 https://angular.io/guide/template-statements#syntax
- 模板陳述句不能參考全域命名空間中的任何內容,例如
window或document。 https://angular.io/guide/template-statements#statement-best-practices
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/392326.html
標籤:javascript html 有角的
上一篇:如何在div中渲染兩個物件?
