Angular - 加载完所有 JS 后调用函数

Angular - Call function when all JS has been loaded

我想在加载我的所有文件 (JS) 时调用一个函数(因为我想调用这些文件之一中的函数)。 我该怎么做?

     .state('dashboard', {
         url: "/dashboard.html",
         templateUrl: "views/dashboard.html",            
         data: {pageTitle: 'Dashboard'},
         controller: "DashboardController",
         resolve: {
             deps: ['$ocLazyLoad', function($ocLazyLoad) {
                 return $ocLazyLoad.load({
                     name: 'MetronicApp',
                     insertBefore: '#ng_load_plugins_before', 
                     files: [
                         '/assets/global/plugins/morris/morris.css',
                         '/assets/admin/pages/css/tasks.css',

                         '/assets/global/plugins/morris/morris.min.js',
                         '/assets/global/plugins/morris/raphael-min.js',
                         '/assets/global/plugins/jquery.sparkline.min.js',

                         '/assets/admin/pages/scripts/index3.js',
                         '/assets/admin/pages/scripts/tasks.js', 
                         //'/js_custom/dashboard.js', 

                         'js/controllers/DashboardController.js'
                     ] 
                 });
             }]
         }
     })

来源:Metronic 模板 AngularJS 版本

看起来 $ocLazyLoad.load() returns 一个承诺。它应该在所有文件都加载后解决。 docs 中有一个示例与您想要的类似:

[...]
return $ocLazyLoad.load('js/ServiceTest.js').then(function() {
  var $serviceTest = $injector.get("$serviceTest");
  $serviceTest.doSomething();
});