如何将网址转换为iframe可以识别的安全网址链接
<iframe src="{{url}}"></iframe>
答案 0 :(得分:0)
在下面尝试这样
secure-pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer} from '@angular/platform-browser';
@Pipe({ name: 'secure' })
export class SecurePipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}
transform(url) {
return this.sanitizer.bypassSecurityTrustResourceUrl(url);
}
}
app.module.ts
@NgModule({
declarations : [
...
SecurePipe
],
})
以HTML格式
<iframe [src]="url | secure"></iframe>