Created
February 2, 2015 11:52
-
-
Save fesor/90586ca61ad7b5b51de3 to your computer and use it in GitHub Desktop.
$stateDecorator for ionic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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