我确实有一个使用JSON和angular的工作表,我设置我的$ http标头以获取特定.api中的Json,我运行它但是没有出现在我的Json文件中获取$ Http.get,I我想问一下这是否是一个有效的标题,我的意思是我的分隔符有问题吗?
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.0/angular.min.js"></script>
<script type="text/javascript">
var myTable=angular.module('myTable',[]);
myTable.controller('tableCtrl',function($scope,$http){
$http.get ("http://staging.api.sample.com/events.json", {header: {Authorization: 'vsdnmsndjednmsdnjemsdjendmsdnjeNmJHMN'}}); .success(function(response) {
debugger
$scope.members=response.events;
$scope.totals = response.paging;
});
});
答案 0 :(得分:0)
记住正确的风格指南。它应该对你有所帮助。另请查看此链接https://github.com/johnpapa/angular-styleguide/
(function {
'use strict';
angular
.module('myTable', [])
.controller('tableCtrl', tableCtrl);
tableCtrl.$inject = ['$scope', '$http'];
function tableCtrl($scope, $http) {
$http.get("http://staging.api.sample.com/events.json", {
header: {
Authorization: 'vsdnmsndjednmsdnjemsdjendmsdnjeNmJHMN'
}
}).then(function(response.data) {
$scope.members = response.data.events;
$scope.totals = response.data.paging;
}).catch(function(error) {
});
});
}());
此查询错误:
$http.get("http://staging.api.sample.com/events.json", {
header: {
Authorization: 'vsdnmsndjednmsdnjemsdjendmsdnjeNmJHMN'
}
}
你可以通过像这样建立查询来传递参数:
$http.get("http://staging.api.sample.com/customer/1")
或
$http.get("http://staging.api.sample.com/customer/" + some_param)
。如果您想将某个对象发送给您,则应使用POST
。例如:
$http.post("http://staging.api.sample.com/events.json", {object});