Whenever I fetch data from Firebase, I am attempting to redirect accordingly. If the data is null or empty, then there is no need for redirection.
My attempt involves using this.navCtrl.push(ProspectPage);
but for some reason, it is not functioning properly and returns an error.
TypeError: this is null
Below is my code, please review it and advise me on where I may be going wrong.
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { ProspectPage } from '../prospect/prospect';
import * as firebase from 'firebase';
@Component({
selector: 'page-credentials',
templateUrl: 'credentials.html'
})
export class CredentialsPage {
constructor(public navCtrl: NavController) {
}
register(params){
// this.navCtrl.push(ProspectPage); // if i wrote here then it works
ref.orderByChild("ssn").equalTo(1234).on("value", function(snapshot) {
if(snapshot.val())
{
this.navCtrl.push(ProspectPage);
}
});
}
}
In the register()
function, there is a comment. When I add this.navCtrl.push(ProspectPage);
at the beginning of the function, it works. However, it should work when data is retrieved from Firebase.
Below is my HTML code.
<button id="credentials-button1" ion-button color="stable" block on-click="register()"> Let's go! </button>