resolve :
$stateProvider
.state('root', {
abstract: true,
resolve: {
common: ...
},
})
.state('some', {
parent: 'root',
...
});
, .
$route UI Router, . state, , .
$state.get('stateName'), , . - , JS, , resolve, . $state.get('stateName').resolve, .
state resolve , .
angular.module('ui.router.hacked', ['ui.router'])
.config(function ($stateProvider) {
var stateOriginal = $stateProvider.state;
$stateProvider.state = function (name, config) {
config.resolve = config.resolve || {};
return stateOriginal.apply(this, arguments);
}
})
angular.module('app', ['ui.router.hacked']).run(function ($state) {
var state = $state.get('some');
state.resolve.someResolver = ...;
});
Like any other hack, it can have traps and, as a rule, break. Although this method is very simple and simple, it requires additional unit testing and should not be used if conventional methods can be used instead.
estus source
share