javascript - Apply condition on templateUrl in config while routing -


i'm using ui-router , developed multi-lingual website using angular-translate i'm stuck want such scenario:

  1. there 2 template single page 1 normal version english , working normal site , second template consisting of translate="" attribute, in other words translated page. i'm willing if have conditions while routing resolve issue. looking @ code make easier understand.

currently code looks like:

.state('whoweare', {             url: '/about-us',             templateurl: 'templates/whoweare/whoweare.html',              controller: 'whowearectrl'         }     ) 

but i'm want like

    .state('whoweare', {             url: '/about-us',             templateurl: function(istranslated){              if(istranslated){               return "templates/translated/whoweare/whoweare.html";              }              else{                return "templates/whoweare/whoweare.html";              }             },              controller: 'whowearectrl'         }     ) 

but doesn't seems working , have istranslated variable in app.js , can't access in config (routes.js) file me. work around related great. i'm using because when user arrives first time angular translate text seems empty , tags appears empty tags leading towards bad ux. appreciated. !

you can find current state , set template dynamically in app.js

in app.js check state

 $rootscope.$on('$statechangestart', function(event, next) {                  if(next.name=="whoweare" && istranslated)                 {                   next.templateurl="templates/translated/whoweare/whoweare.html";                 }                 else if(next.name=="whoweare" && !istranslated)                {                   next.templateurl="templates/whoweare/whoweare.html";                } 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -