【问题标题】:Error: ng:areq Bad Argument ANGULAR错误:ng:areq 错误参数 ANGULAR
【发布时间】:2016-04-26 14:49:50
【问题描述】:

我正在开发一个 Angularjs 应用程序。 我正在使用ocLazyLoadui.router

我有一个控制器和两个使用chart.jsangular-nvd3 的图表视图。

图形出现但一直报此错误:

错误:ng:areq 错误参数

angular.js:13550 错误:[ng:areq] http://errors.angularjs.org/1.5.5/ng/areq?p0=ChartCtrl&p1=not%20aNaNunction%2C%20got%20undefined 在错误(本机)


我的 app.js::

.state('dashboard.chart',{
    templateUrl:'views/chart.html',
    url:'/chart',
    controller:'ChartCtrl',
    resolve: {
        loadMyFile:function($ocLazyLoad) {
            return $ocLazyLoad.load({
                name:'chart.js',
                files:[
                'bower_components/angular-chart.js/dist/angular-chart.min.js',
                'bower_components/angular-chart.js/dist/angular-chart.css'
                ]
            }),
            $ocLazyLoad.load({
                name:'sbAdminApp',
                files:['scripts/controllers/chartContoller.js']
            })
        }
    }
})
.state('dashboard.graficohora',{
    templateUrl:'views/graficohora.html',
    url:'/graficohora',
    controller:'GraficohoraCtrl',
    resolve: {
        loadMyFile:function($ocLazyLoad) {
            return $ocLazyLoad.load({
                name:'nvd3',
                files:[
                'bower_components/d3/d3.js',
                'bower_components/nvd3/build/nv.d3.js',
                'bower_components/angular-nvd3/dist/angular-nvd3.js',
                ]
            }),
            $ocLazyLoad.load({
                name:'sbAdminApp',
                files:['scripts/controllers/graficohoraController.js']
            })
        }
    }

我的控制器::

angular.module('sbAdminApp')
    .controller('GraficohoraCtrl', ['$scope', '$timeout', function ($scope, $timeout) {
        $scope.options = {
            chart: {
                type: 'pieChart',
                height: 500,
                x: function(d){return d.key;},
                y: function(d){return d.y;},
                showLabels: true,
                duration: 500,
                labelThreshold: 0.01,
                labelSunbeamLayout: true,
                legend: {
                    margin: {
                        top: 5,
                        right: 35,
                        bottom: 5,
                        left: 0
                    }
                }
            }
        };

        getData()
        function getData(){
            $scope.data = [
                {
                    key: "One",
                    y: 5
                },
                {
                    key: "Two",
                    y: 2
                },
                {
                    key: "Three",
                    y: 9
                },
                {
                    key: "Four",
                    y: 7
                },
                {
                    key: "Five",
                    y: 4
                },
                {
                    key: "Six",
                    y: 3
                },
                {
                    key: "Seven",
                    y: .5
                }
            ];
        }


    }]);

我的 HTML::

<div class="row">
    <div class="col-lg-12">
        <h1 class="page-header">Charts</h1>
    </div>
    <!-- /.col-lg-12 -->
</div>
<div class="row">
    <div class="col-lg-12 col-sm-12" id="polar area-chart" ng-controller="ChartCtrl">
        <div class="panel panel-default">
            <div class="panel-heading">Informações sobre Dados Analisados</div>
            <div class="panel-body">
                <div ng-controller="ChartCtrl">
                    <nvd3 options='options' data='data'></nvd3>
                </div>
            </div>
        </div>
    </div>
</div>

你能帮我解决这个错误吗? 谢谢..

【问题讨论】:

标签: angularjs


【解决方案1】:

html 文件上的 ng-controller 放置在错误的位置导致此错误。

【讨论】:

    【解决方案2】:

    您永远不会在您的应用模块中定义“ChartCtrl”。
    将此添加到您的应用程序模块中。

    .controller('ChartCtrl',['$scope', function ($scope) { 
         // add functionality to your controller 
    }]);
    

    【讨论】:

      猜你喜欢
      • 2017-04-24
      • 1970-01-01
      • 2016-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-18
      • 2015-11-03
      相关资源
      最近更新 更多