嗨,请帮助解决代码。如果我嵌入存储在我的项目目录中的静态 HTML 文件,当我在 iframe 中嵌入实时 URL 时,iframe 无法正常工作
这是我的文件夹结构
src
|-app
| |-components
| |-template
| |-template.component.html
| |-template.component.ts
|-assets
|-templates
|-template1
|-index.html
模板.component.html
<iframe [src]="getIframe()" frameborder="0" ></iframe>
模板.component.ts
import { Component, OnInit, Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Component({
selector: 'app-template',
templateUrl: './template.component.html',
styleUrls: ['./template.component.css']
})
export class TemplateComponent implements OnInit {
constructor(private sanitizer:DomSanitizer) { }
ngOnInit() {
}
getIframe(){
console.log('iframe');
return this.sanitizer.bypassSecurityTrustResourceUrl('../../../templates/template1/index.html');
}
}