Wallet/src/js/directives/qrScanner.js
Gustavo Maximiliano Cortez 2e82dfa0a8
Fix QR scanner from directive
2017-01-04 20:43:04 -03:00

36 lines
1,000 B
JavaScript

'use strict';
angular.module('copayApp.directives')
.directive('qrScanner', function($state, $rootScope, $log, $ionicHistory) {
return {
restrict: 'E',
scope: {
onScan: "&"
},
replace: true,
template: '<a on-tap="openScanner()" nav-transition="none"><i class="icon ion-qr-scanner"></i></a>',
link: function(scope, el, attrs) {
scope.openScanner = function() {
$log.debug('Opening scanner by directive...');
$ionicHistory.nextViewOptions({
disableAnimate: true
});
$state.go('scanner', { passthroughMode: 1 });
};
var afterEnter = $rootScope.$on('$ionicView.afterEnter', function() {
if($rootScope.scanResult) {
scope.onScan({ data: $rootScope.scanResult });
$rootScope.scanResult = null;
}
});
// Destroy event
scope.$on('$destroy', function(){
afterEnter();
});
}
}
});