【问题标题】:Angularjs existing controller is undefinedAngularjs现有控制器未定义
【发布时间】:2014-01-05 06:50:37
【问题描述】:

我正在构建更大的 Angular 应用程序,但我只有一个控制器有问题,它们都是相同的,但这个总是未定义的。模块已加载,否则 angular 会崩溃。

我的应用程序结构如下所示...

angular.module("myAPP", [
 "ui.router",
 "ui.bootstrap",
 "ngSanitize",
 "ngAnimate",
 "templates",
 "factories",
 "filters",
 "myAPP.actions",
 "myAPP.users",
 "myAPP.pages",
 "myAPP.index",
 "myAPP.categories",
 "myAPP.packages",
 "myAPP.shops",
 "myAPP.stats" 
])

子模块看起来一样:

angular.module("myAPP.actions",  [
 "myAPP.actions.detail",
 "myAPP.actions.new",
 "myAPP.actions.list",
 "myAPP.actions.edit"
])
.controller("ActionsCtrl",
(
 $scope,
 titleService
) ->
 titleService.setTitle "Actions"
)

我得到了

Error: [ng:areq] Argument 'ActionsCtrl' is not a function, got undefined

所以我尝试调用队列

queue = angular.module("koukejakupuj.actions")._invokeQueue
console.log(queue)

看起来控制器已加载:

[Array[3]]
 0: Array[3]
  0: "$controllerProvider"
  1: "register"
  2: Arguments[2]
   0: "ActionsCtrl"
   1: function ($scope, titleService) {...

我不知道哪里出了问题。

//编辑: 代码在coffeescript中!

【问题讨论】:

    标签: angularjs coffeescript angularjs-controller


    【解决方案1】:

    试试这个:-

    angular.module("myAPP.actions",  [
    "myAPP.actions.detail",
    "myAPP.actions.new",
    "myAPP.actions.list",
    "myAPP.actions.edit"
    ])
    .controller("ActionsCtrl",function( $scope, titleService) {
    // your controller code here.
    }
    );
    

    希望对你有帮助。

    【讨论】:

      【解决方案2】:

      两天后终于想通了。

      重构后我忘记删除具有相同名称的控制器的文件,非常糟糕的失败/错误。

      【讨论】:

        猜你喜欢
        • 2015-08-03
        • 2015-03-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多