javascript 角度错误:'参数'控制器'不是函数,未定义'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21061773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 19:57:36  来源:igfitidea点击:

Angular error: 'argument 'Controller' is not a function, got undefined'

javascriptangularjs

提问by Melbourne2991

I'm guessing there must be something obvious I have missed, this is the second angular app I am building and I have never had this issue before..

我猜一定有一些明显的东西我错过了,这是我正在构建的第二个角度应用程序,我以前从未遇到过这个问题..

Seems both of my controllers are receiving this error. I have confirmed that controllers.js gets loaded and console.log(angcomControllers)does return an object. Other than that I am lost.

似乎我的两个控制器都收到此错误。我已经确认controllers.js 被加载并console.log(angcomControllers)返回一个对象。除此之外,我迷路了。

index.html:

索引.html:

<!doctype html>
<html class="no-js" lang="en" data-ng-app="angcomApp">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Foundation</title>
    <link rel="stylesheet" href="stylesheets/app.css" />

    <!--Library/Framework JS-->
    <script src="bower_components/jquery/jquery.js"></script>
    <script src="bower_components/angular/angular.js"></script>
    <script src="bower_components/angular-animate/angular-animate.js"></script>
    <script src="bower_components/angular-resource/angular-resource.js"></script>
    <script src="bower_components/angular-route/angular-route.js"></script>

    <!--script src='https://cdn.firebase.com/v0/firebase.js'></script>
    <script src='https://cdn.firebase.com/libs/angularfire/0.5.0/angularfire.min.js'></script-->

    <!--App JS-->
    <script src="js/app.js"></script>
    <script src="js/animations.js"></script>
    <script src="js/controllers.js"></script>
    <script src="js/filters.js"></script>
    <script src="js/services.js"></script>
     <script src="js/directives.js"></script>
  </head>
  <body>

    <div ng-view class="view-frame"></div>

  </body>
</html>

app.js

应用程序.js

'use strict';

var angcomApp = angular.module('angcomApp',[
    'ngResource',
    'ngRoute',

    'angcomControllers',
    'angcomServices',
]);

angcomApp.config(['$routeProvider', function($routeProvider) {

        $routeProvider.when('/items', {
            templateUrl: 'partials/items.html',
            controller: 'itemsController'
        }).when('/categories', {
            templateUrl: 'partials/categories.html',
            controller: 'categoriesController'
        });
}]);

controllers.js

控制器.js

var angcomControllers = angular.module('angcomControllers', ['angcomServices']);

angcomControllers.controller('itemsController' ['$scope', 'Items', function($scope, Items) {

}]);

angcomControllers.controller('categoriesController' ['$scope', function($scope) {

}]);

items.html

项目.html

<div data-ng-controller="itemsController"></div>

If I need to post any more code please let me know, thanks!

如果我需要发布更多代码,请告诉我,谢谢!

回答by karaxuna

You are missing ,:

你失踪了,

angcomControllers.controller('itemsController', ['$scope', 'Items', function($scope, Items){

}]);