I am coding for android with ionic cli 1.4.3
i have an app in which i navigate to the scanView where the i have a button which scans for barcode this is the plugin https://github.com/wildabeast/BarcodeScanner
It works fine when the scan is success full, but if the user hits the back button without scanning the scanner window closes and the view is also navigated to the back view.
Only the scan window should close and the view should not change, that is the kind of behavior i am looking for.
I am using the Tabs template here is some of my code,
app.js
.state('tab', {
url: '/tab',
abstract: true,
templateUrl: 'templates/tabs.html'
})
.state('tab.home', {
url: '/home',
views: {
'tab-home': {
templateUrl: 'templates/tab-home.html',
controller: 'homeCtrl'
}
}
})
.state('tab.scanView ', {
url: '/scanView',
views: {
'tab-home': {
templateUrl: 'templates/home-scanView.html',
controller: 'scanViewCtrl'
}
}
})
in my controller i have this
$scope.scanBarcode=function(){
$cordovaBarcodeScanner
.scan()
.then(function(barcodeData) {
// Success! Barcode data is here
console.log(barcodeData);//cancelled,text,format
if(!barcodeData.cancelled){//got the data
$scope.search={
code:barcodeData.text
};
}else{ //cancelled by user
//handel backbutton
$ionicPlatform.onHardwareBackButton(function(event) {
event.preventDefault();
event.stopPropagation();
console.log("going back now y");
});
}//else
}, function(error) {//fail callback
// An error occurred with scanner
alert(error);
});
}
So when the scan is cancelled by the user using the back button the view also changes.
How to i prevent that.