【发布时间】:2018-01-09 13:59:54
【问题描述】:
您好,请帮助解决代码。 如果我嵌入存储在我的项目目录中的静态 HTML 文件,当我在 iframe 中嵌入实时 URL 时 iframe 无法正常工作,则 iframe 工作正常
这里是我的文件夹结构
src
|-app
| |-components
| |-template
| |-template.component.html
| |-template.component.ts
|-assets
|-templates
|-template1
|-index.html
template.component.html
<iframe [src]="getIframe()" frameborder="0" ></iframe>
template.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');
}
}
【问题讨论】:
-
您是否仔细检查了该位置?也许尝试将临时文件放入同一个文件夹?
-
将模板文件夹添加到 .angular 文件?不使用 .../.. 从根目录访问文件夹;推荐使用资产文件夹
-
是的,我将 html 文件放在 assets 文件夹中,但它不起作用
-
是的,我多次检查了位置
标签: angular iframe angular4-forms angular4-router angular4-httpclient