I'm new to Angular2 and trying to change the iframe url with the click of a button. Got a couple of obstacles, such as safe urland setting the src for iframe. There is no way to find a good way to change the URL when clicking buttons / links.
How to change iFrame url based on button id?
HTML
<button md-button (click)="updateSrc($event)" id="first" class="top-link">First</button>
<button md-button (click)="updateSrc($event)" id="second" class="top-link">Second</button>
<iframe id="frame" frameborder="0" [src]="changeUrl()"></iframe>
Component
private first_url = "some url";
private second_url = "some other url":
updateSrs(event) {
console.log('Here');
console.log(event.currentTarget.id);
this.reportUrl();
}
;
changeUrl() {
return this.sanitizer.bypassSecurityTrustResourceUrl(this.first_url);
}
source
share