从angularjs中的查询字符串REST API获取数据

时间:2018-05-03 13:30:44

标签: angularjs

假设我们有一个REST API http://example.com:82//api/Test/GetTestSymbols?exchanges=nc&callTypes=eq&symbolLike=infra,我们需要在Angularjs中从此URL获取JSON数据,如何继续?

表显示数据:

<div class="container" data-ng-app="myApp" data-ng controller="myController">

    <table class="table table-striped table-hover">
    <thead>
      <tr>
        <th>Symbol</th>
        <th>CompanyName</th>
        <th></th>
      </tr>
    </thead>
    <tbody>
      <tr data-ng-repeat="Symbol in records">
        <td>{{ Symbol.Symbol }}</td>
        <td>{{ Symbol.CompanyName }}</td>
      </tr>
    </tbody>
  </table>
</div>

var app = angular.module('myApp', []);

app.controller('myController', function($scope, $http, $window) {
  $scope.render = function() {    
    var url = 'http://example.in:82//api/Test/GetTestSymbols?exchanges=nc&callTypes=eq&symbolLike=inf';

    var c = $window.angular.callbacks.counter.toString(36);
    $window['angularcallbacks' + c] = function (data) {
      $window.angular.callbacks['_' + c](data);
      delete $window['angularcallbacks' + c];
    };     

    $http.jsonp('http://example.in:82//api/Test/GetTestSymbols?exchanges=nc&callTypes=eq&symbolLike=infra').then(function(response) {
      $scope.Symbol = response.data.results;
    });
  };

  $scope.render();
});

0 个答案:

没有答案