简体   繁体   English

在 Angular JS 应用程序生命周期中的哪个位置加载此代码

[英]Where in the Angular JS application life cycle does this code load

Based on the code below, can someone tell me where in the Angular JS life cycle this code will be loaded.根据下面的代码,有人可以告诉我在 Angular JS 生命周期的哪个位置加载此代码。 I am running into a very arcane timing issue where sometimes angularjs controllers that need the code below are loaded prior to the code below.我遇到了一个非常神秘的时序问题,有时需要下面代码的 angularjs 控制器会在下面的代码之前加载。 Sometimes I can attempt to reproduce more than 100 times and the issue never occurs.有时我可以尝试重现 100 多次,但问题永远不会发生。 I would like to to force this code to load before any other controllers.我想强制此代码在任何其他控制器之前加载。

(function() {
    'use strict';
angular
    .module('securityMaintenance')
    .directive('buttons', buttons);

function buttons() {
    var directive = {
        restrict: 'AE',
        scope: {},
        templateUrl: 'app/shared/buttons/buttons.html',
        controller: ButtonsController,
        controllerAs: 'vm'
    };

    return directive;
}

ButtonsController.$inject = ['$location', '$route', '$scope', '$rootScope'];

// ReSharper disable once InconsistentNaming
function ButtonsController($location, $route, $scope, $rootScope) {
   ...
   init();

   function init() {}    
}  
  }
})();

This was solved mainly by using a priority member of directive that I found after days of searching in a GitHub repository.这主要是通过使用我在 GitHub 存储库中搜索数天后发现的指令的优先级成员来解决的。 Anyway, it is angular JS and it seemed to have worked.无论如何,它是 angular JS,它似乎奏效了。 The priority member is synonymous with a setting a threads priority or setting the z-index of an html element.优先级成员与设置线程优先级或设置 html 元素的 z-index 同义。 It controls the compilation order of the templates, I guess.我猜它控制模板的编译顺序。

function buttons() {
    var directive = {
        restrict: 'AE',
        priority: 100,
        scope: {},
        templateUrl: 'app/shared/buttons/buttons.html',
        controller: ButtonsController,
        controllerAs: 'vm'
    };

    return directive;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM