Angular2:IFrame未按预期加载

时间:2017-02-16 16:21:30

标签: angular iframe

这是一个非常简单的应用程序,其下方有一个工具栏和全屏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);
  }
 }

0 个答案:

没有答案