Angularjs: how to avoid the route call on first page load

2

I need to make the page fully loaded, without calling any route, when the user accesses the direct link. The problem occurs when the page loads, Angular simply reads the URL path and calls the route. Routes can only be called when I click on a button.

How can I avoid calling the route after page loading?

    
asked by anonymous 03.11.2016 / 00:29

1 answer

0

After so much searching, I did not succeed. But I decided to create my simple method that solved my problem and I know it can help those who have that same doubt.

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 load will be complete, without the need for a second request made by the route. Just click on any button that contains the path of a route that will be triggered normally, not just when the page is loaded by the URL.

    
03.11.2016 / 22:52