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'頁面上改變什麼? –
不,它應該沒問題。 :) –