javascript - Get templateUrl from ui-router -


maybe title isn't clear.

i'm working on 2 nested angular apps. both have own router built ui-router. if call state unknown main router, i'd search state in sub-app router templateurl , url related state.

i thought creating service parser. parse file find data want. solution not best option have, that's why wanted know if there specific function/method in ui-router achieve it. read on ui-router doc, seems not :/

feel free ask more details or suggest solution can match goal :)

you can achieve using dynamic parameters in $stateprovider configuration defined on sub-module. have anchored routes on main module, , if there match, ui-router fetch associated template. if there no matched absolute route/url, ui-router falls on parameterised route, so:

// anchored $stateprovider   .state('mainappstate', {     url: '/anchored',     controller: 'myctrl'  })  // sub module  .state('subappstate', {     url: /:parameter     resolve: { // use resolve , $stateparams parameter can make request api }     templateprovider: { // inject service , use call backend } 

you can use parameter, gets passed $stateparams, gets passed resolve block functions, can retrieve data or process data $stateparams, can used templateprovider provide meaningful fallback url. that's because templateprovider receives resolves. wait promises in resolve block resolve 1 way or before executing.

that way can catch unmatched urls main app in sub app. hope helps.

see issue here: ui-router: async data in templateurl function

oh , 1 more thing - if going mangle js in build process, make sure define templateprovider function .$inject = [ ... ]. if not, you'll unknown provider error. ngannotate not catch dependencies in templateprovider function. alternatively can use /* @nginject */, worked me.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -