Reputation: 2087
I'm trying to replace a URL
using (<HTMLInputElement>document.getElementById("workflow")).src
however I don't think this is the right way of doing it.
Also tried the code below but its giving me getElementById
of undefined.
import { Component, ElementRef, Inject } from '@angular/core';
constructor(private elementRef: ElementRef){}
this.elementRef.nativeElement.document.getElementById("workflow").src = "./javascript/workfloweditor.html?title="+workFlowTitle;
Can someone point out how to do this properly in Angular 2?
Upvotes: 1
Views: 668
Reputation: 657268
<iframe [src]="iframeSrc">
constructor(private sanitizer:DomSanitizer) {
}
get iframeSrc() {
this.sanitizer.bypassSecurityTrustUrl('./javascript/workfloweditor.html?title='+workFlowTitle);
// or
this.sanitizer.bypassSecurityTrustResourceUrl('./javascript/workfloweditor.html?title='+workFlowTitle);
}
See also https://angular.io/docs/ts/latest/api/platform-browser/index/DomSanitizer-class.html
Upvotes: 1