Why is the page revamped twice the $ContentLoaded?



  • There's a method in the counteraller:

    $rootScope.$on('$viewContentLoaded', function () {
        console.log('$viewContentLoaded');
    });
    

    When the F5 page (cmd + R on the track) has been reloaded in the consolidated method twice.

    And any transition method

    $rootScope.$on('$stateChangeSuccess', function () {
      console.log('$stateChangeSuccess');
    });
    

    It works twice, too.

    Why is this happening?



  • https://stackoverflow.com/questions/31000417/angular-js-viewcontentloaded-loading-twice-on-initial-homepage-load

    This is simply a feature of the implementation of the uiView directive. It launches an event of $viewContentLoaded during initialization (link function). At this point, the state is not yet known, but the event has already been sent.

    The second time is when the U.S.S. service allowed all dependence, uploaded the templates, etc.

    Well, it doesn't happen because of a bad configuration or because of that chubby chip, it's loaded twice. It just works uiView.

    You can even verify this by fully commenting on your definitions for state as well as most of your markings (except the ui-view directive itself). It's gonna work once.

    A little reference code:

    uiView definition of directive:

    {
        restrict: 'ECA',
        terminal: true,
        priority: 400,
        transclude: 'element',
        compile: function (tElement, tAttrs, $transclude) {
          return function (scope, $element, attrs) {
            ...
            updateView(true);
            ...
          }
        }
    }
    

    function updateView:

    function updateView(firstTime) {
      ...
      currentScope.$emit('$viewContentLoaded');
      currentScope.$eval(onloadExp);
    }
    

    You can see the rest of the code. GitHub ♪ https://github.com/angular-ui/ui-router/blob/db68914cd6c821e7dec8155bd33142a3a97f5453/src/viewDirective.js




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2