Reputation:
Afternoon all,
We are a little new to Ionic, we have managed to add the 'cordovaBarcodeScanner' without any issues and we scan scan qr codes and on success state changes but doesn't trigger alert afterwords.
If anyone can see what we are doing wrong this would help massively.
Thank you.
angular.module('starter.controllers', [])
.controller("PetIndexCtrl", function($scope, $rootScope, $state, $cordovaBarcodeScanner) {
$scope.scanBarcode = function() {
$cordovaBarcodeScanner.scan().then(function(result) {
$rootScope.barcoderesults = [{
Result: result.text,
Format: result.format,
Cancelled: result.cancelled
}];
$state.go('tab.pet-detail');
alert(result.text);
}, function(error) {
alert("Scanning failed: " + error);
});
};
});
Upvotes: 1
Views: 8460
Reputation: 7025
So you'd want to start tapping into events from Ui-Router.
.controller('RootCtrl', function($scope, $ionicLoading, $timeout){
$scope.$on('$stateChangeStart',
function(event, toState, toParams, fromState, fromParams){
$ionicLoading.show();
});
$scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
$timeout(function(){
$ionicLoading.hide()
},2000);
});
})
So in this example, I'm just showing a loader when you change states, then hiding after the state change was successful.
Upvotes: 6