我正在一個項目中,我有一套練習,當我點擊練習時,我導航到其他頁面,您可以播放本練習的視頻。我現在要做的是以下情況:ìonic2 - 如何動態設置頁面
這是我的Home.html:
<ion-card *ngIf="oefening1" (click)="navigate(oefening1, oefening2, oefening3, oefening4)">
<img src="assets/img/{{ oefening1 }}.jpg"/>
<ion-card-content>
<ion-card-title>{{ oefening1 }}</ion-card-title>
<p>Setjes: {{ set1 }}</p>
<p>Herhalingen: {{ rep1 }}</p>
</ion-card-content>
<ion-card *ngIf="oefening2" (click)="navigate(oefening2, oefening1, oefening3, oefening4)">
<img src="assets/img/{{ oefening2 }}.jpg"/>
<ion-card-content>
<ion-card-title>{{ oefening2 }}</ion-card-title>
<p>Setjes: {{ set2 }}</p>
<p>Herhalingen: {{ rep2 }}</p>
</ion-card-content>
</ion-card>
這是home.ts我的導航功能:
navigate(exercise, exercise2, exercise3, exercise4){
this.navCtrl.push(ExercisePage, {
clickedExercise: exercise,
secondExercise: exercise2,
thirdExercise: exercise3,
fourthExercise: exercise4
});
}
這是我的exercise.html:
<ion-content padding overflow-scroll="true">
<ion-grid>
<ion-row>
<ion-col col-12>
<div (click)="playVid()" padding-bottom>
<img *ngIf="fullPath" [src]="fullPath"/>
</div>
<div text-center>
<button ion-button block [disabled]="!disabledBtn">Block Button</button>
<button ion-button round (click)="nextExercise()">Voltooi</button>
</div>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
個
而且exercise.ts:
export class ExercisePage {
public clickedExercise: any;
public secondExercise: any;
public thirdExercise: any;
public fourthExercise: any;
public fullPath: string;
public disabledBtn: boolean;
constructor(public navCtrl: NavController, private streamingMedia: StreamingMedia, public params:NavParams) {
this.clickedExercise = params.get("clickedExercise");
this.secondExercise = params.get("secondExercise");
this.thirdExercise = params.get("thirdExercise");
this.fourthExercise = params.get("fourthExercise");
this.disabledBtn = false;
}
playVid(){
console.log('video completed');
setTimeout(() => {
this.disabledBtn = true;
}, 10000);
// Playing a video.
let options: StreamingVideoOptions = {
successCallback:() => { console.log('Video played') },
errorCallback: (e) => { console.log('Error streaming') },
orientation: 'portrait'
};
this.streamingMedia.playVideo('http://www.sylvanreinieren.com/fysioWebapp/videos/'+ this.clickedExercise + '.mp4', options);
}
ionViewWillEnter() {
this.fullPath = "assets/img/" + this.clickedExercise + ".jpg";
// console.log('secondExercise:',this.secondExercise, 'ThirdExercise: ', this.thirdExercise, 'Fourth: ', this.fourthExercise);
}
nextExercise(){
this.clickedExercise = this.secondExercise;
this.secondExercise = this.thirdExercise;
this.thirdExercise = this.fourthExercise;
this.navCtrl.push(ExercisePage, {
clickedExercise: this.secondExercise,
secondExercise: this.thirdExercise,
thirdExercise: this.fourthExercise
});
console.log('nextExercise', this.clickedExercise);
}
}
所以基本上我想達到的目標是,當我點擊按鈕,nextExercise下一個練習有展現的方法,但它似乎跳過第二行使。當它通過所有練習時,它必須回到家中。
有誰知道如何正確實現這一點?
我認爲在每個練習中使用幻燈片而不是頁面會更好。我可以分享一個代碼,但我需要知道一件事,你是在進入該頁面時播放視頻還是用戶必須點擊「播放」才能開始播放? –
@GabrielBarreto @GabrielBarreto你必須點擊「play」,因此我現在所做的並不是爲每一個單獨的練習創建一個頁面,而是通過變量clickedExercise – Sreinieren