@dana
To get the HTML content from an iframe in Angular, you need to access the contentWindow property of the iframe element and then use the document property of the contentWindow to access the HTML content. Here's an example of how you can achieve this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import { Component, ViewChild, ElementRef, AfterViewInit } from '@angular/core'; @Component({ selector: 'app-iframe', template: '<iframe #myIframe></iframe>' }) export class MyComponent implements AfterViewInit { @ViewChild('myIframe') iframe: ElementRef; ngAfterViewInit() { const iframeContent = this.iframe.nativeElement.contentWindow.document.body.innerHTML; console.log(iframeContent); } } |
Note that accessing the contents of an iframe from a different domain can lead to cross-origin issues. You may need to configure your server to allow cross-origin requests or use a proxy server to work around these issues.