Wallet/src/js/directives/qrScanner.js

36 lines
1,000 B
JavaScript
Raw Normal View History

2015-07-23 11:48:28 +03:00
'use strict';
angular.module('copayApp.directives')
.directive('qrScanner', function($state, $rootScope, $log, $ionicHistory) {
2016-05-31 16:52:38 -03:00
return {
restrict: 'E',
scope: {
onScan: "&"
2016-05-31 16:52:38 -03:00
},
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 });
};
2017-01-04 20:43:04 -03:00
var afterEnter = $rootScope.$on('$ionicView.afterEnter', function() {
if($rootScope.scanResult) {
scope.onScan({ data: $rootScope.scanResult });
$rootScope.scanResult = null;
}
});
2017-01-04 20:43:04 -03:00
// Destroy event
scope.$on('$destroy', function(){
afterEnter();
});
}
2016-05-31 16:52:38 -03:00
}
});