0
应用程序有一个带3个仪表板按钮的顶部栏。每个链接通过iframe在页面上打开一个新的仪表板。
app.component.htmlAngular 2:更新路由器url获取更改时的iframe src
<md-toolbar class="toolbar">
<span>Dashboardds</span>
<span class="spacer"></span>
<button md-button [routerLink]="['/dashboard', 'first']" id="first" class="top-link">First</button>
<button md-button [routerLink]="['/dashboard', 'second']" id="second" class="top-link">Second</button>
<button md-button [routerLink]="['/dashboard', 'third']" id="third" class="top-link">Third</button>
</md-toolbar>
<router-outlet></router-outlet>
app.module.ts
{path: 'dashboard/:id', component: DashboardComponent},
{path: '', redirectTo: 'dashboard/first', pathMatch: 'full'},
{path: '**', redirectTo: 'dashboard/first', pathMatch: 'full'}
控制板组件是非常简单的。它有3个网址和1个iframe。
dashboard.component.html
export class DashboardComponent implements OnInit, OnChanges {
dashboardUrl: SafeUrl;
first_url: string = "first url of the dashboard";
second_url:string="second url of the dashboard";
third_url:string="third url of the dashboard";
constructor(private route: ActivatedRoute, private sanitizer: DomSanitizer) {
//console.log("Constructor "+route.snapshot.params['id']);
this.dashboardUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.first_south_url);
}
ngOnInit() {
this.dashboardUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.first_south_url);
}
ngOnChanges(changes: SimpleChanges){
}
}
dashboard.component.html
<iframe id="report-frame" frameborder="0" [src]="dashboardUrl"></iframe>
我如何可以根据按键更新iframe网址点击顶栏并重新加载使用iframe新的网址?
我需要的'app.component.html'页面上改变什么? –
不,它应该没问题。 :) –