【发布时间】:2019-06-18 17:53:15
【问题描述】:
我正在尝试打开一个应用程序。当我提供静态 URL 时,它工作正常。但是当我在 *ngFor 中创建一个动态 href 标记时,我可以看到在 URL 之前添加了 unsafe 关键字并且它不起作用。
我在 Angular 6 上运行。并在服务中获取 Id。在 ngFor 中,我正在循环结果并创建带有 Id 的链接以打开应用程序。我创建了一个管道,但它仍然无法正常工作。
安全管道
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({
name: 'safeurl'
})
export class SafeurlPipe implements PipeTransform {
constructor(private domSanitizer: DomSanitizer) {}
transform(value: any) {
return this.domSanitizer.bypassSecurityTrustUrl(value);
}
}
在组件中,我在 ngFor 标记之间添加了以下行
<a href="appName://joinTournament?id={{t.tag}} |safeurl">Join</a>
【问题讨论】: