ngCamg
Use camera with ionic framework and also action sheets (With options to take photo from album)
Install
bower install ngCamg
Example
app.js
(function() {
'use strict';
angular
.module('app', ['ionic', 'controller', 'ngCamg'])
.run(Platform)
.config(Config);
////////////////////////////////////////////////////////////////////////////
function Platform($ionicPlatform){
$ionicPlatform.ready(function() {
console.log('start ionic');
});
}
function Config($stateProvider, $urlRouterProvider){
$stateProvider
.state('camera', {
url: '/camera',
templateUrl: 'index.html',
controller: 'CameraController'
});
$urlRouterProvider.otherwise('camera');
}
})();
controller.js
(function() {
'use strict';
angular
.module('controller')
.controller('CameraController', CameraController);
CameraController.$inject = ['$scope', '$ngCamg', '$ionicServices'];
function CameraController($scope, $ngCamg, $ionicServices) {
// Send your base64 file to some place...
$scope.getPic = function(photoType) {
$ngCamg
.getPicture(photoType)
.then(function(data) {
console.log(data);
});
};
// Show action sheet when click camera button
$scope.optionsCamera = function () {
var buttons = [{ text: 'Take Picture'}, {text: 'Pictures from Library'}];
$ionicServices.actionSheet(buttons, 'Options', 'Cancel', photoTypeCamera);
};
/*------------------------------------------------------------------------*/
// Choose what kind of type you want to get
function photoTypeCamera(index) {
if (typeof Camera !== 'undefined') {
switch (index) {
case 0:
$scope.getPic(Camera.PictureSourceType.CAMERA);
break;
case 1:
$scope.getPic(Camera.PictureSourceType.SAVEDPHOTOALBUM);
break;
}
} else {
$scope.getPic();
}
return true;
}
/*------------------------------------------------------------------------*/
}
})();
index.html
<ion-nav-view>
<button class="button button-default" ng-click="optionsCamera()">
<i class="ion-camera"></i>
</button>
</ion-nav-view>