如何从angularjs中的url加载json数据

时间:2014-03-06 19:41:22

标签: angularjs angularjs-directive angularjs-scope angularjs-ng-repeat

我试图在angularjs中创建图表。它工作正常,但我不知道,如何在 loadingtracking 变量中绑定json url中的数据。请帮帮我。

myApp.controller('AppCtrl', ['$scope', '$filter', 'Data', function ($scope, $filter, Data) {

    // Defining app scope
    $scope.app = {}
    $scope.app.data = Data;
    $scope.app.message = "In AppCtrl";

    // Define table data
    var shipmenttracking = [{ "OrderNumber": "SA00887342", "Airwaybill": "2013-09-05 12:12:36", "Status": "Postpayment", "Elapsed": "Puma" }];


    $scope.app.shipmenttracking = shipmenttracking;

} ]);

1 个答案:

答案 0 :(得分:0)

以下是从URL

获取JSON对象响应的代码
myApp.controller('AppCtrl', ['$scope', '$filter', 'Data', function ($scope, $filter, $http, Data) {

    // Defining app scope
    $scope.app = {}
    $scope.app.data = Data;
    $scope.app.message = "In AppCtrl";

    var configObject = {
        method : 'GET',
        url : '<page-name-goes-here>'
        reponseType : 'text/javascript'
        };


        $http(configObject)
        .success(function(data){
            $scope.app.shipmenttracking = data;
        });

} ]);