这是资源
hq.factory('AvgUsersPerWeek', function ($resource) {
return $resource('/HQ/Graph/GetLoggedinUsersPerWeek')
});
控制器
hq.controller('AvgUsersPerWeekCtrl', function ($scope, AvgUsersPerWeek) {
$scope.xkey = 'Period';
$scope.ykeys = ['CountUsers'];
$scope.labels = ['Aantal'];
$scope.myModel = AvgUsersPerWeek.query();
/*
//example dataset that works, the fetched data has the same structure
[
{ "Period": "2013-04", "CountUsers": 2407 },
{ "Period": "2013-03", "CountUsers": 3351 },
{ "Period": "2013-02", "CountUsers": 2469 },
{ "Period": "2013-01", "CountUsers": 2246 },
{ "Period": "2012-12", "CountUsers": 3171 },
{ "Period": "2012-11", "CountUsers": 2155 },
{ "Period": "2012-10", "CountUsers": 1226 },
{ "Period": "2012-09", "CountUsers": 2245 }
]; */
})
据透露。如果我用下面的数据集替换AvgUsersPerWeek.query(),它就可以工作。因此,我的资源出现了问题(提取(Fiddler)),但值不会插入到我的图表中。
我已经进行了双重检查,示例数据集具有与由数据集获取的数据集相同的结构$资源。
我没有封闭的HTML,因为它的作品。我想有什么东西在路上我使用$资源。
查询的结果是什么?你可以登录'AvgUsersPerWeek.query()'吗? – 2014-09-05 08:27:38
[{“Period”:“34”,“CountUsers”:19},{“Period”:“35”,“CountUsers”:9}]。我用我的测试数据替换了这些值,以检查图表是否已加载并确实存在。 – NicoJuicy 2014-09-05 08:43:36
好,你有正确的数据。但$资源使用承诺,这是异步的,所以当范围初始化时,承诺可能无法解决 – 2014-09-05 08:49:10