im using anuglarjs , morris create graph.
i have directive as:
app.directive('barchart', function() { return { // required make work element restrict: 'e', template: '<div></div>', replace: true, // observe , manipulate 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 }); } }; }); my service data api:
services.factory('temp', function ($resource) { return $resource('http://localhost/api/temp', {}, { query: { method: 'get', isarray: true} }) }); and controller:
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); }]); the problem error: cannot read property 'label' of undefined. api returns json array looks this:
[{"date":"20150717105501","temp":"26","humidity":"38"}, {"date":"20150717105401","temp":"26","humidity":"38"}, {"date":"20150717105301","temp":"26","humidity":"37"}, {"date":"20150717105101","temp":"36","humidity":"0"}] i dont see problem, im new angular. thank you!
Comments
Post a Comment