我尝试使用 Restangular 来处理对我的 Restful API 的调用。
这是我的代码:
var baseStories = Restangular.all('stories/all');
baseStories.getList().then(function (stories) {
console.log(stories);
})
Run Code Online (Sandbox Code Playgroud)
console.log 显示完整的重新角度化数组,而不是我期望的故事数组。
我使用文档中的 RestangularProvider.addResponseInterceptor 来解包响应数据。
有人知道我错过了什么吗?
编辑: 下面是上面代码的 console.log 输出的屏幕截图。我看到两个故事(这是正确的)和一堆 Restangular 方法。是否可以只获取故事?
我想用Angular JS和Restangular将对象发送到Spring Controller.这就是我尝试这样做的方式:
var scoreTO = {
score: parseFloat($scope.score.score),
percentage: parseFloat($scope.score.percentage),
date: (new Date()).getTime()
}
Restangular.one("scores").post(scoreTO);
Run Code Online (Sandbox Code Playgroud)
有运输对象:
public class ScoreTO implements Serializable{
private double score;
private double percentage;
private long date;
public ScoreTO(){}
public ScoreTO(double score, double percentage, long date){
this.score = score; this.percentage = percentage; this.date=date;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public double getPercentage() {
return percentage;
}
public void setPercentage(double percentage) {
this.percentage = percentage;
} …Run Code Online (Sandbox Code Playgroud) 使用Restangular,get方法/ promise将解析,但传递给.then()的结果为空...使用console.log(data); 显示未定义.我检查了chrome debug中的网络选项卡,xhr请求很好,200次成功...正文中有一个完整的json响应.
使用addResponseInterceptor,我发现data参数是未定义的,但response参数显示包含带有负载/ body的data属性的对象.
所以,我还在挠头......为什么数据参数未定义,而响应对象在response.data中正确包含json有效负载/响应?
我需要解决这个问题,以便在解析时将结果传递给.then().
createNode: function(node) {
var account = "9936";
var eventId = "0fd6afd9-4aa0-a5c9-ff0b3e60cdcf";
Restangular.addResponseInterceptor(function(data, operation, what, url, response, deferred) {
console.log("````````````````");
console.log(data);
console.log(operation);
console.log(what);
console.log(url);
console.log(response);
console.log(deferred);
console.log("````````````````");
});
Run Code Online (Sandbox Code Playgroud)
node.js:12
undefined node.js:13
get node.js:14
event node.js:15
/1.0/loadbalancers/account/9936/event/0fd6afd9-4aa0-a5c9-ff0b3e60cdcf node.js:16
^Object {data: Object, status: 200, headers: function, config: Object}
config: Object
data: Object
Automation: Object
Classification: Array[2]
ExecutionTimestamp: "2014-08-13T16:08:37.4676Z"
ID: "0fd6afd9-a5c9-ff0b3e60cdcf"
Incident: Object
LastStatus: "ENQUEUED"
Metadata: Object
Name: "Node Create"
RecordLogs: false
Source: "Device …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序:
app.js:
angular.module('AngApp', [
'angularGrid'
]);
Run Code Online (Sandbox Code Playgroud)
我自己的restangular service.js:
var app = angular.module('AngApp');
app.factory('restService', ['Restangular', function (Restangular) {
// make use of Restangular
}
]);
Run Code Online (Sandbox Code Playgroud)
和controller.js:
var app = angular.module('AngApp');
app.controller('ctrlAG', ['$scope', '$http', '$log', '$mdDialog',
'Restangular',function ($scope,$http, $log, $mdDialog, Restangular) {
// make use of other modules and Restservice
}
]);
Run Code Online (Sandbox Code Playgroud)
HTML是:
<script type="text/javascript" src="ng/app.js"></script>
<script type="text/javascript" src="ng/restangular.js"></script>
<script type="text/javascript" src="ng/restService.js"></script>
<script type="text/javascript" src="ng/ctrlAG.js"></script>
<script type="text/javascript" src="ng/ctrlMetadata.js"></script>
Run Code Online (Sandbox Code Playgroud)
角度1.3.6,restangular(最新).
我接受这个错误的原因是什么?我已经检查了这里常见的错误, 但是没有错误存在.