Reputation: 191
I am trying to pass data to home page after a user login in ionic. In home page if I did this:
ionViewDidLoad() {
console.log(this.navParams.get('username'));
}
The username would be displayed. But if I do this:
constructor(public navCtrl: NavController, public
navParams:NavParams,
public loadingCtrl:LoadingController) {
this.username = this.navParams.get('username');
}
ionViewDidLoad() {
console.log(username);
}
The error below is being displayed:
ReferenceError: 'username' is not defined
I already did this:
data:any;
username:any;
members: Array<any>;
loader: any;
I want to be able to call the username anywhere in the page.
Upvotes: 0
Views: 2312
Reputation: 397
in your .html file the input field that you use to for username
<input type="text" [(ngModel)]="username">
and in
ionViewDidLoad() {
console.log(this.username);
}
Upvotes: 1