2016-01-15 38 views
-1

我想在iPad上使用ionic和插件上傳多張圖片。如何使用離子和科爾多瓦插件從i pad gallery上載多個圖像?

我正在一個錯誤

Uncaught Error: [$injector:modulerr] Failed to instantiate module starter due to: 
Error: [$injector:modulerr] Failed to instantiate module ngCordova due to: 
Error: [$injector:nomod] Module 'ngCordova' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. 

我沒有得到如何準確使用該插件+如何測試是否其工作或沒有?

app.js

var app = angular.module('starter', ['ionic','ngCordova']); 

app.run(function($ionicPlatform) { 
    $ionicPlatform.ready(function() { 
     // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
     // for form inputs) 
     if(window.cordova && window.cordova.plugins.Keyboard) { 
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
     } 
     if(window.StatusBar) { 
      StatusBar.styleDefault(); 
     } 
    }); 
}); 

app.controller('ImagePickerController', function($scope, $cordovaImagePicker, $ionicPlatform, $cordovaContacts) { 

    $scope.collection = { 
     selectedImage : '' 
    }; 

    $ionicPlatform.ready(function() { 

     $scope.getImageSaveContact = function() {  
      // Image picker will load images according to these settings 
      var options = { 
       maximumImagesCount: 1, // Max number of selected images, I'm using only one for this example 
       width: 800, 
       height: 800, 
       quality: 80   // Higher is better 
      }; 

      $cordovaImagePicker.getPictures(options).then(function (results) { 
       // Loop through acquired images 
       for (var i = 0; i < results.length; i++) { 
        $scope.collection.selectedImage = results[i]; // We loading only one image so we can use it like this 

        window.plugins.Base64.encodeFile($scope.collection.selectedImage, function(base64){ // Encode URI to Base64 needed for contacts plugin 
         $scope.collection.selectedImage = base64; 
         $scope.addContact(); // Save contact 
        }); 
       } 
      }, function(error) { 
       console.log('Error: ' + JSON.stringify(error)); // In case of error 
      }); 
     }; 

    }); 

這是我在plunker代碼。

+0

如果您安裝了正確的[ngCordova](http://ngcordova.com/docs/install/)插件,然後在** index.html **中添加了** ng-cordova.js **腳本,那麼首先您檢查。 –

+0

我已經安裝了ng-cordova插件,並且包含它也 – Anky

+0

你在瀏覽器或應用程序中嘗試的地方。 –

回答

0

我的app.js文件。

var app = angular.module('starter', ['ionic','ngCordova']); 

app.run(function($ionicPlatform) { 
    $ionicPlatform.ready(function() { 
     // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
     // for form inputs) 
     if(window.cordova && window.cordova.plugins.Keyboard) { 
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
     } 
     if(window.StatusBar) { 
      StatusBar.styleDefault(); 
     } 
    }); 
}); 

app.controller('ImagePickerController', function($scope, $cordovaImagePicker, $ionicPlatform, $cordovaContacts) { 

    $scope.collection = { 
     selectedImage : '' 
    }; 

    $ionicPlatform.ready(function() { 
alert("hiii"); 
     $scope.getImageSaveContact = function() {  
      // Image picker will load images according to these settings 
      var options = { 
       maximumImagesCount: 1, // Max number of selected images, I'm using only one for this example 
       width: 800, 
       height: 800, 
       quality: 80   // Higher is better 
      }; 

      $cordovaImagePicker.getPictures(options).then(function (results) { 
       // Loop through acquired images 
       for (var i = 0; i < results.length; i++) { 
        $scope.collection.selectedImage = results[i]; // We loading only one image so we can use it like this 

        window.plugins.Base64.encodeFile($scope.collection.selectedImage, function(base64){ // Encode URI to Base64 needed for contacts plugin 
         $scope.collection.selectedImage = base64; 
         $scope.addContact(); // Save contact 
        }); 
       } 
      }, function(error) { 
       console.log('Error: ' + JSON.stringify(error)); // In case of error 
      }); 
     }; 

    }); 

    $scope.contact = {  // We will use it to save a contact 

     "displayName": "Gajotres", 
     "name": { 
      "givenName" : "Dragannn", 
      "familyName" : "Gaiccc", 
      "formatted" : "Dragannn Gaiccc" 
     }, 
     "nickname": 'Gajotres', 
     "phoneNumbers": [ 
      { 
       "value": "+385959052082", 
       "type": "mobile" 
      }, 
      { 
       "value": "+385914600731", 
       "type": "phone" 
      }    
     ], 
     "emails": [ 
      { 
       "value": "[email protected]", 
       "type": "home" 
      } 
     ], 
     "addresses": [ 
      { 
       // "type": "home", 
       "formatted": "Some Address", 
       "streetAddress": "Some Address", 
       "locality":"Zagreb", 
       "region":"Zagreb", 
       "postalCode":"10000", 
       "country":"Croatia" 
      } 
     ], 
     "ims": null, 
     "organizations": [ 
      { 
       "type": "Company", 
       "name": "Generali", 
       "department": "IT", 
       "title":"Senior Java Developer" 
      } 
     ], 
     "birthday": Date("08/01/1980"), 
     "note": "", 
     "photos": [ 
      { 
       "type": "base64", 
       "value": $scope.collection.selectedImage 

      } 
     ], 
     "categories": null, 
     "urls": null 
    }   

    $scope.addContact = function() { 
     $cordovaContacts.save($scope.contact).then(function(result) { 
      console.log('Contact Saved!'); 
     }, function(err) { 
      console.log('An error has occured while saving contact data!'); 
     }); 
    }; 

}); 

運行x代碼裏面的代碼否則它會一直顯示錯誤cordova沒有定義。