0

我想在加载所有文件(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 Template AngularJS 版本

4

1 回答 1

1

看起来像是$ocLazyLoad.load()回报了一个承诺。当所有文件都已加载时,它应该被解决。文档中有一个示例与您想要的类似:

[...]
return $ocLazyLoad.load('js/ServiceTest.js').then(function() {
  var $serviceTest = $injector.get("$serviceTest");
  $serviceTest.doSomething();
});
于 2015-08-15T18:26:10.530 回答