Ionic 2相机错误

时间:2016-08-20 18:39:55

标签: javascript html angularjs ionic-framework camera

所以我正在Ionic 2中构建一个应用程序,我有一个访问相机的功能,但由于某种原因,它不起作用,该功能甚至没有正确执行。 以下是相关的HTML和JS文件,以及控制台日志的屏幕截图。非常感谢任何帮助!

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);
        });
    }
}

控制台 enter image description here

enter image description here

1 个答案:

答案 0 :(得分:3)

takePicture应该在引号中......

(click)="takePicture()"