返回对象时的Angular infdig错误
Angular infdig Error When Returning Object
我是Angular的新手,遇到了这样的情况:我必须在ng-repeat中将一个对象传递给元素的属性。如果我不使用ajax获取数据,只返回一个普通对象,那么在返回新对象时代码可以正常工作,但是,当我这样做时,就会得到一个错误。我的问题是什么是最好的方法来做我正在做的代码下面,也解决我的错误。提前谢谢你。
HTML元素内ng-repeat:
<div ng-if="currentView.comparisons !== 'null'">
<div ng-repeat="comparison in currentView.comparisons track by $index" class="row x-margintop">
<div class="row x-margintop">
<div class="col-md-8">
<fusioncharts width="100%" height="400px" type="column2d" datasource="{{getComparisonChart(comparison)}}"></fusioncharts>
</div>
</div>
</div>
</div>
JS:
/*Ajax For Getting Comparisons Omitted For Brevity But Comparisons Will Have
The Following Properties*/
var newCompObj = {name: comparison.name, template : comparison.template, dataSource: comparison.dataSource, date: {startDate: null, endDate: null}};
$scope.currentView.comparisons.push(newCompObj);
$scope.getComparisonChart = function(chart){
//Callback and Other Chart Data Will Vary Based On The Chart Type
if(chart.dataSource === 'SvC'){
var data = [];
/* here I want to make a callback and return some data and have that data as part of the returned object. I know this code is wrong, but not sure how to do this */
$http({
url:'callbacks/chart_data/dogCallback.jsp',
method: 'GET',
params: {startDate: chart.startDate, endDate: chart.endDate}
}).success(function(data){
setData(data);
});
function setData(data){
return {
"chart": {
"caption": "Monthly revenue for last year",
"subCaption": "Harry's SuperMart",
"xAxisName": "Month",
"yAxisName": "Revenues (In USD)",
"numberPrefix": "$",
"paletteColors": "#0075c2",
"bgColor": "#ffffff",
"borderAlpha": "20",
"canvasBorderAlpha": "0",
"usePlotGradientColor": "0",
"plotBorderAlpha": "10",
"placevaluesInside": "1",
"rotatevalues": "1",
"valueFontColor": "#ffffff",
"showXAxisLine": "1",
"xAxisLineColor": "#999999",
"divlineColor": "#999999",
"divLineDashed": "1",
"showAlternateHGridColor": "0",
"subcaptionFontBold": "0",
"subcaptionFontSize": "14",
"theme": "fint"
},
"data": data,
};
}
};
问题是我可以有许多fusioncharts,所以我不会有$scope。每一个都是Var。用户可以使用该图表类型创建任意数量的图表,并且该类型的每个图表都需要相同的对象,但将具有不同的数据。关于如何解决这个问题,我愿意接受任何想法。总之,我有一个元素需要一个对象作为它的数据源。图表的类型定义了对象和我使用ng-repeat重复的对象的其他属性,定义了必须通过回调返回的数据的参数。我还尝试了对象内嵌的Ajax调用,但没有成功。
如果您还需要其他信息请告诉我。
最后回到这个问题。不确定这对其他人是否有帮助。我最终做的是使用一个null数据对象的对象,然后在ng-repeat完成后设置数据对象。
if(startDate != null && endDate != null && (vsData != null && vsData.length > 0)){
if(comparison.dataSource === 'svcChart'){
$http({
url:'callbacks/chart_data/Sales_StoreVsCountry.jsp',
method: 'GET',
params: {store: comparison.store, country: vsData, startDate: startDate, endDate: endDate}
}).success(function(data){
var chartObj = $scope.svcChart;
chartObj.data = data;
FusionCharts(chartId).setJSONData(chartObj);
});
}
}
相关文章:
- Node.js v6.2.0类扩展不是函数错误
- Jquery菜单操作不稳定,定位不正确,存在一般错误
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- 试图在引导模式内动态生成图表,得到offsetWidth错误
- 为什么会出现错误;未捕获的类型错误:undefined不是函数;
- 我如何修复包含在captcha的addthis中的错误
- Angular JS错误:仅在IE 10和IE 11中出现[$rootScope:infdig]
- AngularJS错误:$rootScope:infdig Infinite$digest循环:达到10次$digest
- 为什么使用CryptoJS的哈希计算会在Angular中导致$rootScope:infdig错误
- AngularJS 错误:$rootScope:infdig 无限$digest循环
- $rootScope:AngularJS应用程序中的infdig错误
- JavaScript 运行时错误:[$rootScope:infdig] 达到 10 次$digest() 迭代.中止!
- 未捕获的错误: [$rootScope:infdig]
- AngularJS:未捕获错误:已达到[$rootScope:infdig]10$digest()迭代
- Angular.js 1.4.7动态ng选项导致多个方法调用和infdig错误
- 在AngularJS中使用ng-disabled来验证元素集合时,会出现$rootScope:infdig错误
- 返回对象时的Angular infdig错误
- <基本href>原因;[$rootScope:infdig]”;错误
- 指令错误 $rootScope:infdig 无限$digest循环
- 错误:[$rootScope:infdig] 10 $digest()迭代到达.流产