ionic.bundle.js类型错误:无法读取属性'添加'的未定义

ionic.bundle.js TypeError: Cannot read property 'add' of undefined

本文关键字:属性 添加 未定义 读取 js bundle 类型 错误 ionic      更新时间:2023-09-26

在运行Android 4.2.2SM-G386F设备上使用cordova插件相机版本1.2.0插件拍照后,我出现以下错误。

我的离子版本是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.Capture image

首先使用命令添加相机插件

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

如果你有任何疑问。请告诉我。感谢