Я использую директиву ng-camera для доступа к веб-камере в моей форме
Я получаю данные изображения URI в scope.snapshot Я хочу получить это в моем контроллере
controllers.js
.controller('visitorController', ($scope) => {
// webcam
$scope.picture = false;
});
directives.js
function directive($q, $timeout) {
return {
restrict: 'E',
scope: {
actionMessage: '@',
captureMessage: '@',
countdown: '@',
flashFallbackUrl: '@',
overlayUrl: '@',
outputHeight: '@',
outputWidth: '@',
shutterUrl: '@',
viewerHeight: '@',
viewerWidth: '@',
cropHeight: '@',
cropWidth: '@',
imageFormat: '@',
jpegQuality: '@',
snapshot: '=',
},
// 'templateUrl': '/angular/ng-camera.html',
template: ['<div class="ng-camera">',
'<div class="ng-camera-countdown" ng-if="countdown" ng-show="activeCountdown">',
'<p class="tick">{{countdownText}}</p>',
'</div>',
'<div class="ng-camera-stack">',
'<img class="ng-camera-overlay" ng-if="overlayUrl" ng-show="cameraLive" ng-src="{{overlayUrl}}" alt="overlay">',
'<div id="ng-camera-feed"></div>',
'</div>',
'</br>',
'<button id="ng-camera-action" ng-click="getSnapshot()">{{actionMessage}}</button>',
'</div>'].join(''),
link,
};
function link(scope, element, attrs) {
scope.getSnapshot = function () {
if (scope.countdown !== undefined) {
scope.countdownStart();
scope.countdownPromise.promise.then(() => {
$timeout(() => {
scope.activeCountdown = false;
scope.countdownText = parseInt(scope.countdown);
}, 2000);
if (scope.shutterUrl !== undefined) {
scope.shutter.play();
}
Webcam.snap((data_uri) => {
scope.snapshot = data_uri;
console.log(scope.snapshot);
});
});
} else {
if (scope.shutterUrl !== undefined) {
scope.shutter.play();
}
Webcam.snap((data_uri) => {
scope.snapshot = data_uri;
});
}
};
scope.$on('$destroy', () => {
Webcam.reset();
});
}
}
Как это пройти? Можно ли передать объем директивы в контроллер?
Я использую эту нг-камеру: https://github.com/bcabanes/ng-camera