Angular $ http服务,Steam DotA 2 API

时间:2017-03-01 17:03:43

标签: javascript angularjs api http get

我刚开始使用AngularJS,我有一个关于$ http服务和从Web服务器接收数据的问题,我制作了这个简单的脚本,应该从Steam的DotA2 API获取JSON但是出于某种原因它& #39;没有获取数据,这里分别是index.html和script.js:

<html ng-app="steamPowered">

<head>
    <script data-require="angular.js@1.3.0-beta.5" data-semver="1.3.0-beta.5" src="https://code.angularjs.org/1.3.0-beta.5/angular.js"></script>
    <script src="script.js"></script>
    <title>
        Angular
    </title>
</head>

<body ng-controller="MainController">

    <div>
        <p>{{errx}}</p>
    </div>

    <div>
        <p>Player ID: {{levat.result.players[0].account_id}}</p>
    </div>

</body>

</html> 

的script.js

(function() {
    var nesscafe = angular.module("steamPowered", []);

    var MainController = function($scope, $http) {
        var apikey = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
        var matchID = prompt("Enter match ID: ")
        var returnedObject = function(response) {
            $scope.levat = response.data;
        }
        var onError = function() {
            $scope.errx = "ERROR: https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/V001/?match_id=" + matchID + "&key=" + apikey;
        }            $http.get("https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/V001/?match_id=" + matchID + "&key=" + apikey)
        .then(returnedObject, onError);
    }
    nesscafe.controller("MainController", MainController);
 }());

0 个答案:

没有答案