Advertisement
Shariska

profile page ts file

Nov 11th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. import { Component, NgZone } from '@angular/core';
  2. import { NavController, NavParams, App } from 'ionic-angular';
  3.  
  4. import { AngularFireAuth } from 'angularfire2/auth';
  5. import * as firebase from 'firebase';
  6.  
  7. import { PurchasePage } from '../purchase/purchase';
  8. import { WelcomePage } from '../welcome/welcome';
  9. import { EditprofilePage } from '../editprofile/editprofile';
  10. import { User } from '../../models/user';
  11. import { UsercrudProvider } from '../../providers/usercrud/usercrud';
  12.  
  13. @Component({
  14. selector: 'page-me',
  15. templateUrl: 'me.html',
  16. })
  17. export class MePage {
  18. user = {} as User;
  19. avatar: any;
  20.  
  21. constructor(public navCtrl: NavController, public navParams: NavParams,
  22. public afAuth: AngularFireAuth, private app: App, public userservice: UsercrudProvider,
  23. public zone: NgZone, ) {
  24.  
  25. }
  26.  
  27. ionViewWillLoad() {
  28. this.loaduserdetails();
  29. }
  30.  
  31. loaduserdetails() {
  32. this.userservice.getUserDetails().then((res: any) => {
  33. this.zone.run(() => {
  34. this.avatar = res.photoURL;
  35. })
  36. })
  37. }
  38.  
  39. ionViewDidLoad() {
  40. console.log('ionViewDidLoad EditprofilePage');
  41. var person = firebase.auth().currentUser;
  42. var uid = person.uid;
  43.  
  44. const profileDetails = firebase.database().ref(`userprofile/${uid}`);
  45. profileDetails.on('value', snapshot => {
  46. this.user = snapshot.val();
  47. console.log('profileDetails',this.user);
  48. });
  49. }
  50.  
  51.  
  52.  
  53. myprofile() {
  54. this.navCtrl.push(EditprofilePage);
  55. }
  56.  
  57. PurchasePage() {
  58. this.navCtrl.push(PurchasePage);
  59. }
  60.  
  61. // editprofile(){
  62. // this.navCtrl.push(EditprofilePage);
  63. // }
  64.  
  65. onLogout() {
  66. this.afAuth.auth.signOut()
  67. .then(() => {
  68. this.navCtrl.setRoot(WelcomePage);
  69. // this.nav.rootNav.setRoot(WelcomePage);
  70. this.app.getRootNav().setRoot(WelcomePage);
  71. console.log('logout');
  72. }).catch(function (error) {
  73. // An error happened.
  74. });
  75. }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement