【问题标题】:ng:areq Argument is not a function, got undefined in AngularJSng:areq 参数不是函数,在 AngularJS 中未定义
【发布时间】:2015-06-26 07:02:16
【问题描述】:

我正在尝试使用 angularjs 使 div 可排序(拖放)。我制作了一个运行良好的演示。但是当我在项目中实现时,它给出了一个错误。

看看下面的代码。

<div ng-app="reportingModule">
<div class="container-fluid" ng-controller="sortableController" ng-init="chartCollection = @JsonConvert.SerializeObject(chartViewModelCollection)">
    <ul id="dashboard" ui-sortable ng-model="chartCollection">
        <li ng-repeat="chart in chartCollection" ng-style="setColour(chartCollection.length)">
            <div>
                ...
                ...
                ...
            </div>
        </li>
    </ul>
</div>

我有两个 JS 文件用于维护代码标准。

排序JS.js

angular.module('reportingModule', ['ui.sortable'])
.controller("sortableController", function ($scope) {
    var tmpList = [];
    $scope.sortingLog = [];

    $scope.sortableOptions = {
        stop: function (e, ui) {
            // this callback has the changed model
            var logEntry = tmpList.map(function (i) {
                return i.value;
            }).join(', ');
            $scope.sortingLog.push('Stop: ' + logEntry);
        }
    };
})

ReportingMenu.js:

angular.module('reportingModule')
    .controller('reportingMenuController', ["$rootScope", "$scope", "chartDetailsService", "reportingFocus", function ($scope, $rootScope, chartDetailsService, reportingFocus) {
        ...
        ...
        ...
 ])

我收到[ng:areq] Argument 'reportingMenuController' is not a function, got undefined 错误。

当我从sorting.js 文件中删除['ui.sortable'] 时,错误消失了..但排序也不起作用。

【问题讨论】:

    标签: jquery angularjs jquery-ui sorting


    【解决方案1】:

    如 Angular module guide page 的“创建与检索”部分所述,

    请注意,使用 angular.module('myModule', []) 将创建 模块 myModule 并覆盖任何名为 myModule 的现有模块。采用 angular.module('myModule') 检索现有模块。

    所以,看起来您要么有另一个文件在创建“reportingModule”模块,要么这些文件的顺序不正确。我的错误是前者。

    确保模块只被创建一次(只有一个文件有 angular.module('reportingModule', [...]))并确保该文件是第一个模块文件在您的 index.html 中引用。

    【讨论】:

      猜你喜欢
      • 2016-11-12
      • 1970-01-01
      • 2015-09-02
      • 2015-10-20
      • 2014-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多