0

我正在尝试使用 oclazyload 模块延迟加载我的 JS 文件。但我收到了这个错误

未捕获的 ReferenceError:dashboardController 未定义

当我的文件正确加载时。这是状态声明

.state(
    "dashboard",
    {
        url : "/dashboard",
        views : {

             "mainbody" : {
                 templateUrl : "dashboard/dashboard.html"
             },
         },
         resolve : {
             load : [
                 '$ocLazyLoad',
                 function($ocLazyLoad) {
                     return $ocLazyLoad
                         .load({
                             name : 'Dashboard',
                             files : [
                                'dashboard/Dashboard.js',
                                'dashboard/controllers/DashboardController.js' 
                             ]
                        });
                } 
            ]
        },
        data : {
            pageTitle : "dashboard",
            authenticate : true
        }
    })

我的模块是这样声明的:

angular.module('Dashboard', [ 'nvd3', 'ngAnimate', 'ui.bootstrap', 'ngTouch', 'ui.grid' ]).controller('dashboardController', dashboardController);

和控制器

function dashboardController ($scope , uiGridConstants, $http,  $timeout) {//some staff}

知道如何解决吗?

4

2 回答 2

0

尝试将解析块放在您的视图块下

.state(
    "dashboard", {
    url : "/dashboard",
    views : {
        "mainbody" : {
            templateUrl : "dashboard/dashboard.html",
            resolve : {
                load : [
                    '$ocLazyLoad',
                    function ($ocLazyLoad) {
                        return $ocLazyLoad
                        .load({
                            name : 'Dashboard',
                            files : [
                                'dashboard/Dashboard.js',
                                'dashboard/controllers/DashboardController.js']
                        });
                    }
                ]
            },
            data : {
                pageTitle : "dashboard",
                authenticate : true
            }
        },
    }
})
于 2016-03-29T18:38:58.173 回答
0

请试试这个。

 return $ocLazyLoad
 .load([
      'dashboard/Dashboard.js',
      'dashboard/controllers/DashboardController.js' 
 ]);
于 2016-03-29T18:50:54.420 回答