1313// limitations under the License.
1414
1515import {
16- Component , Input , Output , OnInit , ViewChild , ElementRef , EventEmitter , OnChanges , SimpleChange , Optional
16+ Component , Input , Output , ViewChild , ElementRef , EventEmitter , OnChanges , SimpleChange , Optional
1717} from '@angular/core' ;
1818import { DomSanitizer , SafeResourceUrl } from '@angular/platform-browser' ;
1919import { NavController , Platform } from 'ionic-angular' ;
@@ -30,7 +30,7 @@ import { CoreUrl } from '@singletons/url';
3030 selector : 'core-iframe' ,
3131 templateUrl : 'core-iframe.html'
3232} )
33- export class CoreIframeComponent implements OnInit , OnChanges {
33+ export class CoreIframeComponent implements OnChanges {
3434
3535 @ViewChild ( 'iframe' ) iframe : ElementRef ;
3636 @Input ( ) src : string ;
@@ -43,6 +43,7 @@ export class CoreIframeComponent implements OnInit, OnChanges {
4343
4444 protected logger ;
4545 protected IFRAME_TIMEOUT = 15000 ;
46+ protected initialized = false ;
4647
4748 constructor ( logger : CoreLoggerProvider ,
4849 protected iframeUtils : CoreIframeUtilsProvider ,
@@ -59,9 +60,15 @@ export class CoreIframeComponent implements OnInit, OnChanges {
5960 }
6061
6162 /**
62- * Component being initialized .
63+ * Init the data .
6364 */
64- ngOnInit ( ) : void {
65+ protected init ( ) : void {
66+ if ( this . initialized ) {
67+ return ;
68+ }
69+
70+ this . initialized = true ;
71+
6572 const iframe : HTMLIFrameElement = this . iframe && this . iframe . nativeElement ;
6673
6774 this . iframeWidth = this . domUtils . formatPixelsSize ( this . iframeWidth ) || '100%' ;
@@ -116,6 +123,11 @@ export class CoreIframeComponent implements OnInit, OnChanges {
116123 }
117124
118125 this . safeUrl = this . sanitizer . bypassSecurityTrustResourceUrl ( CoreFile . instance . convertFileSrc ( url ) ) ;
126+
127+ // Now that the URL has been set, initialize the iframe. Wait for the iframe to the added to the DOM.
128+ setTimeout ( ( ) => {
129+ this . init ( ) ;
130+ } ) ;
119131 }
120132 }
121133}
0 commit comments