我正在尝试替换 URL
使用(<HTMLInputElement>document.getElementById("workflow")).src
但我认为这不是正确的做法。
还尝试了下面的代码,但它给了我 getElementById
未定义。
import { Component, ElementRef, Inject } from '@angular/core';
constructor(private elementRef: ElementRef){}
this.elementRef.nativeElement.document.getElementById("workflow").src = "./javascript/workfloweditor.html?title="+workFlowTitle;
有人可以指出如何在 Angular 2 中正确执行此操作吗?
最佳答案
<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);
}
另请参阅https://angular.io/docs/ts/latest/api/platform-browser/index/DomSanitizer-class.html
关于javascript - 在 Angular 2 中通过 DOM 更改 iframe url 的更好方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39528820/