12/3試了 ionic 2 動態載入iframe src但需要使用DomSanitizer bypassSecurityTrustResourceUrl 的方式,
今天試了另一種方式,範例如下:
1.cart.ts檔
import { Component, ViewChild, ElementRef } from '@angular/core';
import { IonicPage } from 'ionic-angular';
import { AlertController } from 'ionic-angular';
import { DomSanitizer } from '@angular/platform-browser';
@IonicPage()
@Component({
selector: 'page-cart',
templateUrl: 'cart.html'
})
export class CartPage {
@ViewChild('ifr') ifr: ElementRef;
loading: any;
constructor(public alertCtrl: AlertController, private sanitizer: DomSanitizer) {
}
ionViewDidLoad() {
this.ifr.nativeElement['src'] = 'https://warrant.xxxxx.com.tw/xxxxweb/';
this.presentLoading();
}
presentLoading() {
this.loading = this.alertCtrl.create({
title: '下載中...',
message: '測試訊息',
buttons: [{
text: 'Ignore',
role: 'cancel'
}, {
text: 'View',
handler: () => {
//this.nav.push(DetailsPage, { message: '測試訊息-2' });
console.log('測試訊息-2 handler');
}
}]
});
this.loading.present();
}
dismissLoading(){
this.loading.dismiss();
}
}
2.cart.html
<iframe data-tap-disabled="true" style="height:100%;width:100%;" src="https://www.xxx.com.tw/" #ifr/>
