2016-01-15 14 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/), то добавили ** ng-cordova.js ** script в ** index.html ** или нет, сначала вы проверить. –

+0

Я установил плагин ng-cordova и включил его также – Anky

+0

где вы пытаетесь в браузере или в приложении. –

ответ

0

мой файл приложения.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 не определен.

 Смежные вопросы

  • Нет связанных вопросов^_^