javascript - Makes 2 states share a part of resolve -
i have defined 2 states follows:
app.config(['$stateprovider', function ($stateprovider) { $stateprovider .state('edit', { url: '/edit/{id}', templateurl: '/htmls/h1.html', controller: 'samectrl', onenter: ...sameonenter... resolve: { ...commonresolve... } }) .state('addinedit', { url: '/addin/edit/{id}', templateurl: '/htmls/h2.html', controller: 'samectrl', onenter: ...sameonenter... resolve: { special: [ ... ], ...commonresolve... } }) }])
so share same controller, same onenter
, , have very long , common part resolve
(which chain of resolves: first: function (...){...}, second: function (...){...}, ...
). know how rewrite them don't have write commonresolve
twice?
just create function resolver:
app.config(['$stateprovider', function ($stateprovider) { resolverfunction.$inject = ['resolvera', 'resolverb']; function resolverfunction(myservice1, myservice2) { return 'something'; } resolverafunction.$inject = ['resolverc']; function resolverafunction(resolverc) { return 'anything'; } resolverbfunction.$inject = ['resolverc']; function resolverbfunction(resolverc) { return 'something else'; } resolvercfunction.$inject = ['service']; function resolvercfunction(service) { return 'something else'; } $stateprovider .state('edit', { url: '/edit/{id}', templateurl: '/htmls/h1.html', controller: 'samectrl', onenter: ...sameonenter... resolve: { commonresolver: resolverfunction, resolvera: resolverafunction, resolverb: resolverbfunction, resolverc: resolvercfunction, } }) .state('addinedit', { url: '/addin/edit/{id}', templateurl: '/htmls/h2.html', controller: 'samectrl', onenter: ...sameonenter... resolve: { special: [ ... ], commonresolver: resolverfunction, resolvera: resolverafunction, resolverb: resolverbfunction, resolverc: resolvercfunction, } }) }])
Comments
Post a Comment