简体   繁体   English

angular.js http.get() 服务不工作

[英]angular.js http.get() service not working

I'm not exactly sure where I'm going wrong but when I put my data into a separate .json file and used $http.get() to retrieve that data my scatter chart isn't visualizing anymore.我不确定我哪里出错了,但是当我将数据放入单独的 .json 文件并使用 $http.get() 检索该数据时,我的散点图不再可视化了。 Here's my code: http://plnkr.co/edit/bJE8qTG8CEI957xKMh6q?p=preview这是我的代码: http : //plnkr.co/edit/bJE8qTG8CEI957xKMh6q?p=preview

Specifically these lines I feel I might be making a mistake:特别是这些行,我觉得我可能犯了一个错误:

$http.get('data.json').success(function(response){
    $scope.exampleData = response.data;

the $http.get() works fine. $http.get()工作正常。

There is an error below:下面有一个错误:

app.controller('ExampleCtrl', [$scope, $http, function ($scope, $http){

should be应该

app.controller('ExampleCtrl', ['$scope', '$http', function ($scope, $http){

and your json doesn't contain a data prop so change $scope.exampleData = response.data;并且您的 json 不包含data道具,因此更改$scope.exampleData = response.data; to this $scope.exampleData = response;到这个$scope.exampleData = response;

also

var colorArray = ['#000000', '#660000', '#CC0000', '#FF6666', '#FF3333', '#FF6666', '#FFE6E6'];
$scope.colorFunction = function(){ 
  return function(d, i){
    return colorArray[i]; 
  };
}

needs to be in a controller;需要在控制器中; you get $scope is undefined if it isn't如果不是,则 $scope 未定义

edit编辑

PSL is right, there is no data prop in the object, but still the original plnkr had errors in it. PSL是对的,对象中没有data道具,但原始的plnkr仍然有错误。 The get() worked just fine which was answering OPs question. get()工作得很好,正在回答 OP 问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM