After all my research, I was unsuccessful. But I decided to create my simple method that solved my problem and I know that can help anyone who has this same question.
Code:
angular.module("myApp", [])
.run(function($rootScope) {
// privates
var isPageLoaded = false;
// constructs
$rootScope.$on("$routeChangeStart", function(event, next, current) {
if (!isPageLoaded) {
isPageLoaded = true;
event.preventDefault();
}
});
});
Now your page loading will be complete, without the need for a second request made by route. Just click on a button contenting the path of a route it will be triggered normally, just not when the page is loaded by the URL.
How is the loading of your app and scripts in your html? You are using
ng-app
or by manually starting the app withangular.bootstrap()
?– Giovane
I’m still using
ng-app
. As I am developing the project, I will need to useangular.bootstrap
to start the app manually. And the loading of the scripts is being on-demand. That is, the user loads only the app files. s and Routes.js for the app setup, and as it navigates the pages, other files will be uploaded along with your controllers.– Renan Coelho
Hm, how do you make this shipment on-demand? Uses Requirejs?
– Giovane
As your user browses it loads apps, routers, and controllers? If so, how are you doing? Which route component are you using?
– Giovane
I’m using the ocLazyLoader.
– Renan Coelho
Damn, I didn’t know this ocLazyLoad, I won’t be able to help you in this issue but thank you for commenting on this component.
– Giovane
Oops! Happy to help! Take a look at my last question asked here at Stack Angularjs: how to work with file-separated controllers. It was there that a guy referred me to ocLazyLoader. But anyway, thank you. I will continue to pursue this issue.
– Renan Coelho