Skip to content

Instantly share code, notes, and snippets.

@fesor
Created February 2, 2015 11:52
Show Gist options
  • Select an option

  • Save fesor/90586ca61ad7b5b51de3 to your computer and use it in GitHub Desktop.

Select an option

Save fesor/90586ca61ad7b5b51de3 to your computer and use it in GitHub Desktop.
$stateDecorator for ionic
angular
.module('fsIonicStateDecorator', ['ionic', 'ui.router'])
.config(function ($provide) {
$provide.decorator('$state', stateDecorator);
})
;
function stateDecorator ($delegate, $injector) {
var $ionicHistory;
$delegate.replace = function (state, params, options) {
options = options || {};
options.location = 'replace';
if (!$ionicHistory) {
$ionicHistory = $injector.get('$ionicHistory');
}
// set previous view as current one
$ionicHistory.currentView($ionicHistory.backView());
// go to target state
return $delegate.go(state, params, options);
};
var originalGo = $delegate.go;
$delegate.go = function (state, params, options) {
return originalGo(state, params, options);
};
return $delegate;
// handle circular dependencies...
// we override $state service of which depends $ionicHistrory
function getIonicHistory() {
if (!$ionicHistory) {
$ionicHistory = $injector.get('$ionicHistory');
}
return $ionicHistory;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment