我正在开发一个Angularjs应用程序。
我正在使用ocLazyLoad
和ui.router
。
我有一个控制器和两个使用chart.js
和angular-nvd3
的图表视图。
图形出现但一直出现这个错误:
错误:ng:areq Bad Argument
和
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']
})
}
}
MY CONTROLLER ::
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>
你可以帮我解决这个错误吗? 感谢..
答案 0 :(得分:0)
html文件上的ng-controller位置错误导致此错误。
答案 1 :(得分:0)
您永远不会定义&#39; ChartCtrl&#39;在您的应用模块中。
将其添加到您的应用模块。
.controller('ChartCtrl',['$scope', function ($scope) {
// add functionality to your controller
}]);