mercredi 11 février 2015

How can I modify a state config before using it in the config phase of Angular?


I want to be able to modify the object I provide the stateHelperProvider.state(obj).


I have a module like this:



(function() {
'use strict';
angular
.module('myApp', [])
.config(stateConfig);

stateConfig.$inject = ['stateConfigObject', 'stateHelperProvider', 'someProvider'];
function stateConfig(stateConfigObject, stateHelperProvider, someProvider) {

someProvider.$get().getSomeData().then(function(response) {
// use the response here to modify the stateConfigObject
});
stateHelperProvider.state(stateConfigObject);
}
})();


I do that, there will be an a-sync issue and the stateConfigObject will not be the correct one passed into the stateHelperProvider in the end. The config phase will probably finish before the a-sync stuff finishes. So, is there anyway to make this all happen synchronously?


I've tried using the stateHelperProvider inside someProvider.$get() like so, but still no luck:



someProvider.$get().getSomeData().then(function(response) {
// use the response here to modify the stateConfigObject
stateHelperProvider.state(stateConfigObject);
});




Aucun commentaire:

Enregistrer un commentaire