Restangular数据,进入$余地列表 [英] Restangular data, getting into $scope for a list
问题描述
已经与API的东西,整天冥思苦想,并决定使用Restanglar。真的有获取数据出来的问题,并在$范围。
Been wrestling with API stuff all day, and decided to use Restanglar. Really having issues getting the data out, and into $scope.
据我所知,这将不仅是一个从API返回的JSON,并有一堆其他的内部方法等。但是,当我得到的数据出来,我可以看到它在控制台调试埋葬的地方.LOG,但我似乎无法得到它变成$范围在我看来,这是pviously工作的罚款$ p $来使用它。
I understand that it won't just be the JSON that is returned from the API, and has a bunch of other internal methods etc. But when I get the data out, I can see it buried somewhere in the debugging with console.log, but I can't seem to get it into $scope to use it in my view which was working fine previously.
我怎样才能得到这些数据,进入我的$的范围,因此,我的看法?
示范
angular.module('horse', ['restangular'])
.config(function(RestangularProvider) {
RestangularProvider.setBaseUrl('http://url/api');
RestangularProvider.setResponseInterceptor(
function(data, operation, what) {
if (operation == 'getList') {
return data[what];
}
return data;
});
});
控制器
angular
.module('horse')
.controller("IndexController", function ($scope, Restangular) {
$scope.horse = null;
$scope.showSpinner = true;
Restangular.all('horse').getList().then(function(horse) {
$scope.horse = horse;
console.log($scope.horse);
});
});
API响应
{"error":false,"horse":[{"id":"1","name":"horse 2"},{"id":"2","name":"horse 2"}]}
编辑1 的
Edit 1
Restangular响应
Restangular response
[Object, Object, route: "horse", getRestangularUrl: function, getRequestedUrl: function, addRestangularMethod: function, clone: function…]
编辑2 的
Edit 2
我也试过这 - https://github.com/ mgonto / restangular#中使用值 - 直在模板
$ scope.horse = Restangular.all(马)的GetList()$对象;
刚刚将导致一个空数组被输出。我也试着删除 setResponseInterceptor
和修改API的结构,直接导致数据阵列,而不元的东西(错误等),没有喜悦:(
Which just results in an empty array being output. I have also tried removing the setResponseInterceptor
and modifying the structure of the api to result the data array directly without the meta stuff (error, etc), no joy :(
推荐答案
数据似乎正在通过。我注意到你正在使用类固醇,你检查的标记,而不仅仅是控制台?
The data seems to be coming through. I notice you're using Steroids, have you checked the markup and not just the console?
请确保您的范围微调设置为false,以确保在数据来通过微调是隐藏的。
Make sure you set the scope spinner to false, to ensure that the spinner is hidden when the data comes through.
$ scope.ShowSpinner = FALSE;
这篇关于Restangular数据,进入$余地列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!