簡體   English   中英

未定義MEAN堆棧角度控制器

[英]MEAN stack angular controller not defined

我很難找出為什么未在MEAN堆棧中定義我的控制器的問題。 每個其他控制器都工作正常。

Error: Argument 'ReportsController' is not a function, got undefined
at assertArg (http://localhost:3000/lib/angular/angular.js:1039:11)
at assertArgFn (http://localhost:3000/lib/angular/angular.js:1049:3).....

app.js

window.app = angular.module('mean', ['ngCookies', 'ngResource', 'ui.bootstrap', 'ui.route', 'mean.system', 'mean.articles', 'mean.reports', 'angularFileUpload']);

angular.module('mean.system', []);
angular.module('mean.articles', []);
angular.module('mean.songs', []);
angular.module('mean.reports', []);

reports.js

angular.module('mean.reports').
controller('ReportsController',
    ['$scope', '$routeParams', '$location', 'Global', 'Reports',
        function ($scope, $routeParams, $location, Global, Reports) {
            $scope.global = Global;
            $scope.find = function() {
                    Reports.query(function(reports) {
                        $scope.reports = reports;
                    }
                );
            };
        }
    ]
);

routes.js

    //report routes
var reports = require('../app/controllers/reports');
app.get('/reports', reports.all);
app.post('/reports', auth.requiresLogin, reports.create);
app.get('/reports/:reportId', reports.show);
app.put('/reports/:reportId', auth.requiresLogin, auth.report.hasAuthorization, reports.update);
app.del('/reports/:reportId', auth.requiresLogin, auth.report.hasAuthorization, reports.destroy);


//Finish with setting up the reportId param
app.param('reportId', reports.report);

編輯:固定-請參閱評論

您收到該錯誤的原因是, reports.js的控制器定義存在錯誤:缺少結論)}] ...

因此,角度函數assertArg()無法將其識別為函數,該函數會引發錯誤。

應該是這樣的(我將其展開以更容易得到錯誤):

angular.module('mean.reports').
    controller('ReportsController', 
        ['$scope', '$routeParams', '$location', 'Global', 'Reports', 
            function ($scope, $routeParams, $location, Global, Reports) {
                $scope.global = Global;
                $scope.find = function() {
                    Reports.query(function(reports) {
                            $scope.reports = reports;
                        }
                    ); // <-- missing
                }; // <-- missing
            } // <-- misssing
        ] // <-- missing
    );
    }; // is seems that should be deleted

每個開口([{應該用)]}適當關閉。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM