I am trying to retrive jsonp data from inside my controller. I want to grab some jsonp data from the url inside $http.jsonp and pass it through a success function that loops through the data and then pushes it into a variable dataxx however I keep getting this error:
Uncaught ReferenceError: myJsonMethod is not defined
angular.module('app', ['onsen'])
.controller('ChartController', ['$scope', '$http', function($scope,$http) {
this.data = [{
key: 'Data',
values: []
}];
$http.jsonp("https://demo8162910.mockable.io/json?callback=myJsonMethod").
success(function(data, status, headers, config) {
//what do I do here?
dataxx.push({"x":9,"y":11},{"x":9,"y":18});
}).
error(function(data, status, headers, config) {
$scope.error = true;
});
$scope.data = [{
key: 'Data',
values: dataxx
}];
}])
.factory('d3', [function() {
return d3;
}])
.factory('nv', [function() {
return nv;
}])
.directive('lineChart', ['d3', 'nv', function(d3, nv) {
return {
restrict: 'E',
scope: {
data: '=',
height: '@',
width: '@'
},
template: '<svg ng-attr-height="{{ height }}" ng-attr-width="{{ width }}"></svg>',
link: function(scope, element) {
var svg = element.find('svg'),
chart;
var update = function() {
d3.select(svg[0])
.datum(scope.data)
.call(chart);
};
scope.$watch(function() { return angular.toJson(scope.data); }, function() {
if (chart) {
update();
}
});
scope.$on('chartloaded', update);
nv.addGraph(function() {
chart = nv.models.lineChart()
.showLegend(false)
.showYAxis(true)
.showXAxis(true);
chart.xAxis
.axisLabel('x')
.tickFormat(d3.format('.2f'));
chart.yAxis
.axisLabel('y')
.tickFormat(d3.format('.2f'));
nv.utils.windowResize(function() {
chart.update()
});
scope.$emit('chartloaded');
return chart;
});
}
}
}]);