I am building my first app using Visual Studio Tools for Apache Cordova (TACO) and running into a problem attempting to use my first Cordova plugin $cordovaImagePicker. I am using Visual Studio 2015 update 2 with version 12.0.60401.1 of the VS Taco extension.
config.xml is set to use version 6.0.0 of the Cordova CLI and I installed version 1.1.0 of the plugin https://github.com/wymsee/cordova-imagePicker.git. My index.html below is pulling in version 1.4.7 of angularjs, 1.1.0 of ionic.js and 0.1.23-alpha of ng-cordova.js.
<!DOCTYPE html>
<html data-ng-app="app">
<head>
<meta charset="utf-8" />
</head>
<body>
<div data-ng-view></div>
<!-- External Libraries -->
<script src="lib/angular.js"></script>
<script src="lib/angular-route.js"></script>
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ng-cordova.js"></script>
<!-- App -->
<script src="scripts/app.module.js"></script>
<script src="scripts/app.js"></script>
<script src="scripts/home.js"></script>
<script src="scripts/dashboard.js"></script>
<!-- Widgets -->
<script src="scripts/widgets/widgets.module.js"></script>
<script src="scripts/widgets/zlTypePlaceholder.js"></script>
<!-- Cordova reference, this is added to your app when it's built. -->
<!-- ReSharper disable once Html.PathError -->
<script src="cordova.js"></script>
<script src="scripts/platformOverrides.js"></script>
</body>
</html>
I am using the @johnpapa Angular 1 style guide
app.js
(function () {
"use strict";
document.addEventListener('deviceready', onDeviceReady.bind(this), false);
function onDeviceReady() {
// Handle the Cordova pause and resume events
document.addEventListener('pause', onPause.bind(this), false);
document.addEventListener('resume', onResume.bind(this), false);
};
function onPause() {
// TODO: This application has been suspended. Save application state here.
};
function onResume() {
// TODO: This application has been reactivated. Restore application state here.
};
})();
app.module.js
(function () {
"use strict";
angular.module('app', [
'ionic',
'ngCordova',
'ngRoute',
'app.widgets'
]);
}
Below in my dashboard.js when I debug this code with visual studio to my android Nexus 5X (Cordova 5.1.0) I get an error when a button is clicked bound to sendImage(). Cannot read property 'getPictures' of undefined but $cordovaImagePicker is an object showing that method when I log it to console it just fails when it hits $cordovaImagePicker.getPictures(options)
(function () {
"use strict";
angular
.module('app')
.controller('Dashboard', Dashboard);
Dashboard.$inject = ['$scope', '$routeParams', '$cordovaImagePicker', '$ionicPlatform'];
function Dashboard($scope, $routeParams, $cordovaImagePicker, $ionicPlatform) {
var vm = this;
vm.sendImage = sendImage;
function sendImage() {
console.log("sendMessage Clicked");
//Import Image
$ionicPlatform.ready(function() {
console.log($cordovaImagePicker);
//TODO: Get Image Picker to work
var options = {
maximumImagesCount: 1,
width: 150,
height: 150,
quality: 100
};
console.log(options);
console.log('here we go...');
$cordovaImagePicker.getPictures(options)
.then(function(results) {
console.log('it worked!');
for (var i = 0; i < results.length; i++) {
console.log(results[i]);
}
}, function(error) {
console.log(error);
});
});
}
}
})();
I would really like to use cordova but if I cant get past this first hurdle I may go the Xamarin route. I don't want to give up easy but please let me know if anything sticks out to you. Thanks!