目前我有一个工作脚本 about.html ,其中包含指向打开模态内容页面的链接:
<div class="wrapper" *ngFor="let detil of detils">
<a (click)="openModal({charNum : 1})">{{detil.contextOne}}</a>
</div>
并在 about.ts
@Component({
selector: 'page-about',
templateUrl: 'about.html'
})
export class AboutPage {
constructor(public navCtrl: NavController, public modalCtrl: ModalController, public http: Http) {
this.http.get('http://example.com')
.map(res => res.json())
.subscribe(data => {
this.detils = data
});
}
}
openModal(characterNum) {
let modal = this.modalCtrl.create(ModalContentPage, characterNum);
modal.present();
}
@Component({
template: `
<div *ngIf="character.image;else other_content">
<iframe #iframeVideo width="100%" height="315px" [src]="trustedVideoUrl ? trustedVideoUrl : null" (load)="trustedVideoUrl ? handleIFrameLoadEvent() : null" frameborder="0" allowfullscreen></iframe>
</div>
</ion-content>
`
})
export class ModalContentPage {
character;
trustedVideoUrl: SafeResourceUrl;
constructor(
public platform: Platform,
public params: NavParams,
public viewCtrl: ViewController,
private domSanitizer: DomSanitizer,
public loadingCtrl: LoadingController
) {
var characters = [
{
image: 'http://www.iframeexample.com'
},
{
image: 'http://www.iframeexample2.com'
}
this.character = characters[this.params.get('charNum')];
this.trustedVideoUrl = this.domSanitizer.bypassSecurityTrustResourceUrl(this.character.image);
}
我想动态地从api获取角色。如何使用http.get实现调用var字符,我尝试使用http.get替换var行。但它无法获得http.get范围内的参数值