Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module( 'x' ).run() will not run asynchronously #38

Open
neekey opened this issue May 15, 2016 · 2 comments
Open

module( 'x' ).run() will not run asynchronously #38

neekey opened this issue May 15, 2016 · 2 comments

Comments

@neekey
Copy link

neekey commented May 15, 2016

Hi, I'm trying to build a SPA which load controllers and templates asynchronously. I have a dashboard module like below:

var html = require( './view.html' );

angular.module( 'app' ). controller( 'dashboardCtrl', function(){
    /../
}); 

and in some point I will dynamically load this module:

require.ensure( [ 'dashboard' ], function(){
   ....
})

In the dev mode, I can see that ngtemplate-loader had generated the correct code, but I can not get the html from $templateCache.get(), then I hack the source code of ngTemplate-loader, add some debug code ( like alert(1) ) into the callback of module( 'x' ).run(), but the hack code is not executed.

I think the problem is that angular.module.run will not be executed again after angular finished its initialization.

I did a little test below:

angular.module( 'app', [] );
angular.module( 'app' ).run(function(){ console.log( 'run 1' ); });    // output: "run 1"

setTimeout(function(){
    angular.module( 'app' ).run(function(){ 
        console.log( 'run 2' );     // never executed.
    });
}, 1000);
@neekey
Copy link
Author

neekey commented May 15, 2016

this #26 seems to solve this problem

@huang-xiao-jian
Copy link

The same issue when define route templateUrl, how do you resolve this? @neekey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants