如何在angular中使用http.get方法来获取json数据?


SHOU宅大可爱
2025-03-21 05:31:03 (11天前)


我创造了一个

漏斗
</跨度>
java脚本中的图表。并转换为angular现在我正在尝试使用angular中的http.get方法来获取json数据。我被困在这里,并在……这一部分感到困惑

现在让我告诉你我的代码部分

— — index.html的

&lt;!DOCTYPE html&gt;
&LT; HTML&GT;
&LT; HEAD&GT;
&lt; meta http-equiv =“content-type”content =“text / html; charset = UTF-8”&gt;
&lt; title&gt; FusionCharts -

漏斗
</跨度>
3D ……

2 条回复
  1. 0# 青年@ | 2019-08-31 10-32



    看来你只是将错误的参数传递给dataSource字段。经过一些玩弄你的羽毛球,

    而不是传递一个执行$ http调用的函数,我传递了数据本身
    </强>
    ,如下所示。




    1. var myApp = angular.module(“myApp”, []);

    2. //The below code will read the data from student.json file and will pass to the $scope variable
      myApp.controller(“ParentCtrl”, function($scope, $http) {

    3. $http.get(‘./chart.json’) //reading the studentRecord.json file
      .success(function(data1) {
      $scope.dataSource = data1; // binding the data to the $scope variable

    4. FusionCharts.ready(function() {
    5.   //alert("1");
    6.   var conversionChart = new FusionCharts({
    7.     type: 'funnel',
    8.     renderAt: 'chart-container',
    9.     width: "100%",
    10.     dataFormat: 'json',
    11.     dataSource: $scope.dataSource
    12.   });
    13.   conversionChart.render();
    14. });
    15. });
      });

    16. </code>


    注意我将代码包装在$ http的成功回调中,这样我们就知道数据在渲染时就存在了。



    你可以看到工作的plunker

    这里



登录 后才能参与评论