Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

How to fetch data getting as return after registration and display in homepage?

$
0
0

@emiljenson wrote:

I have created a registration form and successfully able to save the details to the database. But i couldnt fetch the data getting as return in ionic and display it in homepage ( I need to display name in homepage Eg: Welcome Emil )

Find below the code i wrote in registration.ts

 export class Register {
  responseData:any;
  user = {"name":"","email":"","dob":"","password":""};
  constructor(public navCtrl: NavController, public apiService: ApiService) {
  }

  register() {
    this.apiService.postData(this.user,'register').then((result) => {
      this.responseData = result;
      console.log(this.responseData);
      localStorage.setItem('user',JSON.stringify(this.responseData))
      this.navCtrl.push(HomePage);
    }, (err) => {
        // Error message
     });

  }
}

Find below the code that i wrote in homepage.ts

export class HomePage {
  public userDetails:any;

  constructor(public navCtrl: NavController) {
     const data = JSON.parse(localStorage.getItem('user'));
     this.userDetails = data.user;
     console.log('in home ts');
     console.log(data);
  }

}

console.log(data); return a json string in the following format

Object {name: "fjyh", email: "dfg", token: "CGZUx7RDTbEM1lrzKzQI"}
email :"dfg"
name : "fjyh"
token : "CGZUx7RDTbEM1lrzKzQI"
__proto__ : Object

But console.log( this.userDetails); returns an undefined message.. WHY????

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>