离子与es6:相机未定义

时间:2017-04-01 19:15:26

标签: angularjs ionic-framework ecmascript-6 ngcordova

我一直在研究Ionic与Angular 1.5和ES6的结合,我设法将$ cordovaCamera和$ ionicPlatform注入我的控制器。但是,无法直接使用Camera对象。当我运行项目时,它给了我以下消息:

Uncaught ReferenceError: Camera is not defined
at index.js:261
at Array.<anonymous> (ionic.bundle.js:56238)
at onPlatformReady (ionic.bundle.js:2496)
at onWindowLoad (ionic.bundle.js:2477)

这是我的代码。它与我在另一个空白项目中编写的代码类似,其中Camera实际上最终会被初始化。

class HomeController {

    constructor($cordovaCamera, $ionicPlatform) {
        'ngInject';

        this.$ionicPlatform = $ionicPlatform;
        // this.$ionicPlatform.ready(function(){
        console.log("ready");
        this.$cordovaCamera = $cordovaCamera;
        //});
    }

  $onInit(){
    let self = this;

      this.$ionicPlatform.ready(function(){
          console.log("ready");
          console.log(self.$cordovaCamera);  
          this.options = {
          quality: 100,
          destinationType: Camera.DestinationType.FILE_URI,
          sourceType: Camera.PictureSourceType.CAMERA,
          encodingType: Camera.EncodingType.JPEG,
          cameraDirection: 1,
          saveToPhotoAlbum: true
        }; 
      });
  }


  takePicture(){
        this.$cordovaCamera.getPicture(options).then(function(imageData) {
            this.imgURI = "data:image/jpeg;base64," + imageData;
        }, function(err) {
            // An error occured. Show a message to the user
        });
  }
}

export default HomeController;

在我的index.js中,我注入了ngCordova和Ionic

import CameraComponent from './camera.component';

const home = angular
    .module('home', [ 'ionic',
     'ngCordova',
    ])
    .component('camera', CameraComponent)
    .config($stateProvider => {
        'ngInject';
        $stateProvider
            .state('home', {
                url: '/home',
                component: 'camera'
            })
    })
    .name;

export default home;

主要问题可能在于es6符号。有没有办法解决这个问题?

0 个答案:

没有答案