ionic barcode scanner issue

I am just starting now with ionic 1.1.6, and trying to develope a simple barcode scanner for android 4.1.2, I found this tutorial: https://github.com/cfjedimaster/Cordova-Examples/tree/master/barcode; my app regularly starts the scanner, reads the code but suddenly closes without errors, so I have no clues for going further; I put the code for the scanner in a service this is the my service:

    .factory('QRScanService', [function () {

  return {
    scan: function(success, fail) {
      cordova.plugins.barcodeScanner.scan(
        function (result) { success(result); },
        function (error) { fail(error); }
      );
    }
  };

}])

and this how I call it:

$scope.login = function() {
  QRScanService.scan(function(result) {
  if (result.cancelled) {
    $ionicModal.fromTemplate('').show().then(function() {
      $ionicPopup.alert({
        title: 'QR Scan Cancelled',
        template: 'You cancelled it!'
      });
    });
  } else {
    $ionicPopup.alert({
      template: 'Result: ' + result.text
    });
  }
}, function(error) {
  $ionicPopup.alert({
    title: 'Unable to scan the QR code',
    template: 'Too bad, something went wrong.'
  });
});


  }