【发布时间】:2017-06-23 19:30:14
【问题描述】:
我有一个基本的 Angular 应用程序,它可以对 API URL 进行 GET 请求调用。返回的数据为 JSON 格式。 API 文档声明如下:
您必须在向 API 发出的每个请求中提供您的 App ID 和密钥。为此,请在您的请求中设置一个 HTTP 授权标头,该标头由您的 ID、后跟一个冒号和您的密钥组成,例如 abc123:xyz789。
如何将其合并到我的基本 HTTP 请求中。我的代码如下。
angular.module('myApp', [])
.controller('MyControler', function($scope, $http) {
$scope.$watch('search', function() {
fetch();
});
$scope.search = "My Search Query";
function fetch() {
$http.get("https://APIURlGoesHere" + $scope.search )
.then(function(response) {
$scope.details = response.data;
});
$http.get("ttps://APIURlGoesHere" + $scope.search)
.then(function(response) {
$scope.related = response.data;
});
}
});
【问题讨论】:
标签: javascript jquery angularjs angularjs-scope