In my lazy loading Ionic 3 app, I have three different pages: "LoginPage," "VideoPage," and "HomePage." On the VideoPage, there is a checkbox that allows users to choose whether to show the video on the next start. The routing flow is as follows:
"LoginPage ==> VideoPage ==> HomePage" (checkbox clicked)
"LoginPage ==> HomePage" (checkbox not clicked)
The app should remember the user's choice even if they return after a long time, possibly using storage values. The LoginPage also features key value logic using storage, which is shown in the code snippet below:
(It might be possible for the VideoPage to output an event/variable to guide the login page on whether to go to the HomePage or VideoPage. I am exploring this approach.)
PS: Feel free to ask any questions or provide suggestions.
Login.html:
<ion-item no-lines>
<ion-label floating>Password</ion-label>
<ion-input type="password"></ion-input>
</ion-item>
<button class="charlotte-button" ion-button icon-left (click)="login()">
<ion-icon class="picto picto-checkbox-active-w"></ion-icon>
Login
</button>
Login.ts:
export class LoginPage {
public password: string = '';
public key: string = 'username';
constructor(
public navCtrl: NavController,
public storage: Storage,
private alertCtrl: AlertController ) {
}
login() {
if (this.password === this.key) {
this.storage
.set(this.key, this.password)
.then(val => this.navCtrl.setRoot('LoginPage'));
} else {
let alert = this.alertCtrl.create({
title: 'Wrong password try again !',
buttons: ['Dismiss']
});
alert.present();
}
}
}
Video.html:
<div class="video-container">
<video controls>
<source src="https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4"
poster="https://peach.blender.org/wp-content/uploads/title_anouncement.jpg?x11217"
type="video/mp4">
</video>
<div class="video-title">Tutorial</div>
</div>
<ion-item no-lines class="checkbox-container">
<ion-label class="diLabel">Show this video at the next start</ion-label>
<ion-checkbox [(ngModel)]="disableVideo"></ion-checkbox>
</ion-item>
Video.ts:
export class VideoPage {
constructor(public navCtrl: NavController, public navParams: NavParams) {}
checkClicked() {
if(this.disableVideo) {
this.navCtrl.setRoot('VideoPage');
} else {
this.navCtrl.setRoot('Homepage');
}
}
}
Home.html: home.ts: No additional code is provided here as it does not directly relate to the current topic.