Skip to content

Commit

Permalink
Step 7.23: Add profile component
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and darkbasic committed Oct 16, 2017
1 parent e9aba64 commit 5a4cc57
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/pages/profile/profile.ts
@@ -0,0 +1,48 @@
import { Component, OnInit } from '@angular/core';
import { Profile } from 'api/models';
import { AlertController, NavController } from 'ionic-angular';
import { MeteorObservable } from 'meteor-rxjs';
import { ChatsPage } from '../chats/chats';

@Component({
selector: 'profile',
templateUrl: 'profile.html'
})
export class ProfilePage implements OnInit {
picture: string;
profile: Profile;

constructor(
private alertCtrl: AlertController,
private navCtrl: NavController
) {}

ngOnInit(): void {
this.profile = Meteor.user().profile || {
name: ''
};
}

updateProfile(): void {
MeteorObservable.call('updateProfile', this.profile).subscribe({
next: () => {
this.navCtrl.push(ChatsPage);
},
error: (e: Error) => {
this.handleError(e);
}
});
}

handleError(e: Error): void {
console.error(e);

const alert = this.alertCtrl.create({
title: 'Oops!',
message: e.message,
buttons: ['OK']
});

alert.present();
}
}

0 comments on commit 5a4cc57

Please sign in to comment.