nvd3 angular error: [$rootscope:infdig] 10 $digest() iterations reached. aborting!
我使用 nvd3 angular 指令收到此错误。当您从视图中修改模型时,会发生此错误。但我不认为我正在这样做。
这是代码:
//controller
var options = getChartOptions();
var data = getChartData();
$scope.chart = {
data: data,
options: options
};
//view
<nvd3 class="metrics-chart" options="chart.options" data="chart.data"></nvd3>
这是完整的控制器:
var options = getChartOptions();
var data = getChartData();
$scope.chart = {
data: data,
options: options
};
function getChartOptions(){
return ChartConfigService.getChartOptions();
}
function getChartData(){
var data = [];
var colors = {
'GET': '#f00',
'POST': '#0f0',
'PUT': '#00f',
'DELETE': '#ff0'
};
var verbs = ['GET', 'POST', 'PUT', 'DELETE'];
verbs.forEach(function(verb){
var i = 0;
var values = [];
var now = moment();
while ( i < 10 ) {
values.push({
x: moment(now).add(i, 'minutes'),
y: Math.round(Math.random() * 10)
});
i++;
}
data.push({
values: values, //values - represents the array of {x,y} data points
key: verb, //key - the name of the series.
color: colors[verb] //color - optional: choose your own line color.
});
});
return data;
}