我正在使用anuglarjs和morris来创建图表。
我的指示是:</ p>
app.directive('barchart', function() {
return {
// required to make it work as an element
restrict: 'E',
template: '<div></div>',
replace: true,
// observe and manipulate the DOM
link: function($scope, element, attrs) {
var data = $scope[attrs.data],
xkey = $scope[attrs.xkey],
ykeys= $scope[attrs.ykeys],
labels= $scope[attrs.labels];
Morris.Bar({
element: element,
data: data,
xkey: xkey,
ykeys: ykeys,
labels: labels
});
}
};
});
我从api获取数据的服务:
services.factory('Temp', function ($resource) {
return $resource('http://localhost/api/Temp', {}, {
query: { method: 'GET', isArray: true}
})
});
我的控制员:
app.controller('sampleController', ['$scope', 'Temp',
function($scope, Temp){
$scope.xkey = 'date';
$scope.ykeys = ['temp', 'humidity'];
$scope.labels = ['Temperature', 'Humidity'];
$scope.myModel = Temp.query();
console.log($scope.myModel);
}]);
问题是我收到此错误:无法读取未定义的属性'label'。我的api返回一个json数组,如下所示:
[{"date":"20150717105501","temp":"26","humidity":"38"},
{"date":"20150717105401","temp":"26","humidity":"38"},
{"date":"20150717105301","temp":"26","humidity":"37"},
{"date":"20150717105101","temp":"36","humidity":"0"}]
我看不出有什么问题,我是角色的新手。谢谢!