ionic.bundle.js TypeError:无法读取未定义的属性'add'

时间:2015-11-13 19:34:06

标签: javascript android cordova ionic-framework ionic

在运行 Android 4.2的 SM-G386F 设备上使用 cordova-plugin-camera 版本1.2.0插件拍照后出现以下错误0.2

我的离子版本是 1.1.0

TypeError: Cannot read property 'add' of undefined
    at Object.jqLite.addClass (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:46098:56)
    at Object.beforeStart (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:40117:17)
    at triggerAnimationStart (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:39950:28)
    at runNextTask (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:37511:5)
    at nextTick (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:37495:7)
    at scheduler (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:37466:5)
    at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:39942:15
    at forEach (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:9163:20)
    at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:39923:9
    at Scope. (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:24560:36)

任何帮助都会非常感激,因为我不知道如何解决这个问题!

非常感谢任何愿意提供帮助的人:)

1 个答案:

答案 0 :(得分:0)

之前我遇到过同样的问题。然后我跟着这个tutorial。我得到了输出

<强> 1.Capture image

首先使用命令

添加Camera插件
cordova plugin add org.apache.cordova.camera

<强> HTML

<button ng-click="takePhoto()">Capture</button>
<li ng-repeat="i in myImage">
    <img ng-src="{{baseURL+i}}">
</li>

<强>控制器

$scope.takePhoto = function() {
    navigator.camera.getPicture(onSuccess, onFail, {
        quality: 75,
        targetWidth: 320,
        targetHeight: 320,
        destinationType: 0,
        saveToPhotoAlbum: true
    });

    function onSuccess(imageData) {
        $scope.imgURI = imageData;
        $scope.myImage.push($scope.imgURI);
        $scope.$apply();

    }

    function onFail(message) {
        alert('Failed because: ' + message);
    }

};

<强> 2.Save photo after capture

如果您想将此照片保存在存储空间中,请同时添加文件插件,

cordova plugin add org.apache.cordova.file

<强>控制器

$scope.takePhoto = function() {
    if (window.cordova) {
        var options = {
            quality: 100,
            destinationType: Camera.DestinationType.FILE_URI,
            sourceType: Camera.PictureSourceType.CAMERA,
            encodingType: Camera.EncodingType.JPEG,
            cameraDirection: 1,
            saveToPhotoAlbum: true
        };
        $cordovaCamera.getPicture(options).then(function(imagePath) {
            $scope.imgURI = imagePath;
            //Grab the file name of the photo in the temporary directory
            var currentName = imagePath.replace(/^.*[\\\/]/, '');
            //Create a new name for the photo
            var d = new Date(),
                n = d.getTime(),
                newFileName = n + ".jpg";
            //Move the file to permanent storage
            $cordovaFile.moveFile(cordova.file.tempDirectory, currentName, cordova.file.dataDirectory, newFileName).then(function(success) {
                //success.nativeURL will contain the path to the photo in permanent storage, do whatever you wish with it, e.g:
                //createPhoto(success.nativeURL);

            }, function(error) {
                //an error occured
            });

        }, function(error) {
            //An error occured
        });
    }
};

如果您有任何疑问,请告诉我。谢谢