在angular 2中更改iframe内元素的属性

在angular 2中更改iframe内元素的属性,iframe,angular,Iframe,Angular,我想在angular 2 typescript中更改iframe内部元素的属性,类似于javascript代码 document.getElementById('iframeId').window.document.getElementById('home-grid').style.visibility=“hidden” 我的字体代码: var iframe = document.getElementById('iframeId'); var insideDoc = iframe.conte

我想在angular 2 typescript中更改iframe内部元素的属性,类似于javascript代码

document.getElementById('iframeId').window.document.getElementById('home-grid').style.visibility=“hidden”

我的字体代码:

var iframe   = document.getElementById('iframeId');
var insideDoc = iframe.contentDocument || iframe.contentWindow.document;
编译代码时出错:

stream.js:74
      throw er; // Unhandled stream error in pipe.
      ^
 Error: ./angularapp/web/component/mainPage/mainPage.ts
←[37m(←[39m←[36m35←[39m,←[36m32←[39m): ←[31merror TS2339: Property 'contentDocument' does not exist on type 'HTMLElement'.←[39m./angularapp/web/component/mainPage/mainPage.ts
←[37m(←[39m←[36m35←[39m,←[36m58←[39m): ←[31merror TS2339: Property 'contentWindow' does not exist on type 'HTMLElement'.←[39m
有没有办法在angular 2中实现这一点?请帮助
@组件({
@Component({
  selector: 'my-app',
  template:`
    <h1>Selecting Number</h1>
    <iframe id="iframeId" src="iframe.html" (load)="onLoad()"></iframe>
  `,
})
export class App {
  onLoad()  {
    var iframe   = document.getElementById('iframeId');
    var iWindow = iframe.contentWindow
    var doc = iframe.contentDocument || iframe.contentWindow.document;
    console.debug(doc);
    console.log(doc.getElementById('foo').innerText);
  }
}
选择器:“我的应用程序”, 模板:` 选号 `, }) 导出类应用程序{ onLoad(){
var iframe=document.getElementById('iframeId'); var iWindow=iframe.contentWindow var doc=iframe.contentDocument | | iframe.contentWindow.document; 控制台调试(doc); log(doc.getElementById('foo').innerText); } }

@Günter Zöchbauer。这个问题不是重复提供的链接,因为我的问题是从angular 2中的iFrame中获取元素,我没有发现任何类似的链接。如果答案已经可用,请分享它的链接。Angular没有什么特别之处,它与JavaScript相同。但是我得到了问题中提到的错误。类型“HtmleElement”上不存在属性“contentWindow”。我需要导入任何东西来实现这一点吗?您的代码看起来不像链接问题的公认答案中的代码。您的问题没有提供足够的信息来调试您的问题。如果你证明你的问题不能用链接的答案解决,我可以重新打开这个问题。我的文件中有类似的步骤。但是我仍然得到上面提到的编译错误。我是否必须导入任何东西才能获得此HTMLElement?请尝试
var iWindow=(iframe).contentWindowvar iframe=document.getElementById('iframeId');var doc=(iframe).contentDocument | |(iframe).contentWindow.document;log(“Iframe返回”,Iframe);console.log(“单据返回”,单据);iframe返回整个文档,而变量“doc”返回null。由于某些原因,加载事件会触发两次,有没有人有相同的问题?很好,请回答“不工作,'ionic cordova run android-lcs'不工作,因为实时重新加载导致错误,只有'ionic cordova run android'工作。谢谢你的回答,现在对我有用了