Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

javascript - Start Angular.js route-segment or ui-router after all translations are loaded

Is there any way, how to start ui-router or route-segment just after translateProvider loads its translations?

I'm using pascal prechts translate filter together with bind once {{:: }} notation. On localhost it works pretty good, but when I test it on remote server, bind once will remove watchers sooner than strings are translated.

So I was wondering if there is some way how to delay routing a little bit.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try to check the native, built-in feature:

$urlRouterProvider.deferIntercept(defer)

Disables (or enables) deferring location change interception.

If you wish to customize the behavior of syncing the URL (for example, if you wish to defer a transition but maintain the current URL), call this method at configuration time. Then, at run time, call $urlRouter.listen() after you have configured your own $locationChangeSuccess event handler.

Check some similar issues:

In one of these links, observe this plunker, where this feature is used like this:

Stop and wait in .config() phase:

.config(['$urlRouterProvider' ...,
    function($urlRouterProvider, ...) {

      // defer execution in config phase
      $urlRouterProvider.deferIntercept();
      ...

Later in .run() phase turn the url hanlding on

.run(['$urlRouter' ...,
  function($urlRouter...) {
    ...
    $http
      .get("modules.json")
      .success(function(data) {
        
        // do some stuff
        // re-enable UI-Router url stuff
    
        $urlRouter.sync();
        $urlRouter.listen();
    
      });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...