user4276463
user4276463

Reputation:

Ionic 2 camera error

So I'm building an app in Ionic 2 and I have a function to access the camera, but for some reason it's not working and the function doesn't even execute properly. Below are the relevant HTML and JS files, as well as screenshots of the console log. Any help is very much appreciated!

app.html

    <ion-menu [content]="content">

    <ion-toolbar>
        <ion-title>Menu</ion-title>
    </ion-toolbar>

    <ion-content>
        <ion-list>
            <button ion-item *ngFor="#p of pages" (click)="openPage(p)">
                {{p.title}}
            </button>
                <ion-slides style="height: 50vh">
                    <ion-slide *ngFor="#image of images">
                        <ion-card>
                            <img [src]="image.src"/>
                        </ion-card>
                    </ion-slide>
                </ion-slides>
        </ion-list>
    </ion-content>
</ion-menu>
<button fab primary fab-bottom fab-center (click)=takePicture() style="z-index: 999">
    <ion-icon name="camera"></ion-icon>
</button>
<script src="camera.js" type="text/javascript"></script>
<ion-nav id="nav" [root]="rootPage" #content swipe-back-enabled="false"></ion-nav>

camera.js

import {Page} from 'ionic-angular';
import {NgZone} from 'angular2/core';
import {Camera} from 'ionic-native';
@Page({
    templateUrl: 'build/pages/app/app.html'
})
    export class HomePage {
    public base64Image: string;
    constructor() {
    }
    takePicture(){
        console.log('click');
        Camera.getPicture({
            destinationType: Camera.DestinationType.DATA_URL,
            targetWidth: 1000,
            targetHeight: 1000
        }).then((imageData) => {
            // imageData is a base64 encoded string
            this.base64Image = "data:image/jpeg;base64," + imageData;
        }, (err) => {
            console.log(err);
        });
    }
}

console enter image description here

enter image description here

Upvotes: 1

Views: 266

Answers (1)

Aaron Saunders
Aaron Saunders

Reputation: 33345

takePicture should be in quotes...

(click)="takePicture()"

Upvotes: 3

Related Questions