这是一个非常简单的应用程序,其下方有一个工具栏和全屏iframe。在我开始动态设置iframe src
之前,一切正常。这是代码:
的 app.component.html
<md-toolbar class="toolbar">
<span>Toolbar</span>
<span class="spacer"></span>
<button md-button (click)="updateDashboard(first_url)" id="first" class="top-link">First Button</button>
<button md-button (click)="updateDashboard(second_url)" id="second" class="top-link">Second Button</button>
</md-toolbar>
<iframe id="report-frame" frameborder="0" [src]="dashboardUrl"></iframe>
app.component.ts
export class AppComponent {
dashboardUrl: SafeUrl;
constructor(private sanitizer: DomSanitizer) {}
private first_url: string = "https://www.google.com/"
private second_url:string="https://reddit.com"
updateDashboard(url: string) {
this.sanitizer.bypassSecurityTrustResourceUrl(url);
}
}