Permalink
Browse files

Step 14.15: Use the getPicture method into messages-attachment.ts

  • Loading branch information...
darkbasic committed Jun 7, 2017
1 parent 12fb8b7 commit ea9cd551d526872723b3ceecc464b941ef01c388
Showing with 30 additions and 8 deletions.
  1. +30 −8 src/pages/messages/messages-attachments.ts
@@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import { ModalController, ViewController } from 'ionic-angular';
import { AlertController, ModalController, Platform, ViewController } from 'ionic-angular';
import { NewLocationMessageComponent } from './location-message';
import { MessageType } from 'api/models';
import { PictureService } from '../../services/picture';
@@ -12,16 +12,26 @@ export class MessagesAttachmentsComponent {
constructor(
private viewCtrl: ViewController,
private modelCtrl: ModalController,
private pictureService: PictureService
private pictureService: PictureService,
private platform: Platform,
private alertCtrl: AlertController
) {}
sendPicture(): void {
this.pictureService.select().then((file: File) => {
this.viewCtrl.dismiss({
messageType: MessageType.PICTURE,
selectedPicture: file
sendPicture(camera: boolean): void {
if (camera && !this.platform.is('cordova')) {
return console.warn('Device must run cordova in order to take pictures');
}
this.pictureService.getPicture(camera, false)
.then((blob: File) => {
this.viewCtrl.dismiss({
messageType: MessageType.PICTURE,
selectedPicture: blob
});
})
.catch((e) => {
this.handleError(e);
});
});
}
sendLocation(): void {
@@ -41,4 +51,16 @@ export class MessagesAttachmentsComponent {
locationModal.present();
}
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 ea9cd55

Please sign in to comment.