Closed navjinder closed 9 years ago
I am not really sure. The .then should pass a parameter that has a .data property.
Wait a minute! I misread your code, if you want to use the asyncCallback, just return the promise:
$scope.thisfunct = function(opt){
return DreamFactory(db).getList();
};
Your code should work for the normal callback, though.
Thanks @nicklasb I have tried that too but now the issue is it do not register it as function.
data seems to be an object with a property, "record". The server should return an array, not an object with a "record" property.
Oh thanks @nicklasb I will see if I can get the api to spit the array rather than the object. Thanks for looking into.
Either that, or you'd have to create some kind of http-promise-fake-proxy with a .then()-function that ASFDS thinks is the actual http promise. It only has to have to put the record on the value.data instead, something like this:
$scope.thisfunct = function(opt) {
this.then = function(successCallback, failureCallback) {
this.successCallback = successCallback;
this.failureCallback = failCallback;
};
DreamFactory(db).getList().then(
function (value) {
value.data = value.data.record
this.successCallback(value);
},
function (value, status) {
this.failureCallback(value);
}
);
return this;
};
I don't know if the above works att all, I have no easy way to test it, its just an idea. Either way, promises are a little bit problematic.
I am thinking that perhaps I should add some onAsyncData callback that is called when the promise is fullfilled, enabling users to transform the data anyway they like, I realize that one is not always in control of the back end.
It worked; so I created a new function and named it getListJson to this file and it works like a charm.
d.getListJson = function(){
return $http.get(DSP_URL + '/db/' + table + '/', { isArray: true,
transformResponse: function(data, headers){
var tempdata = JSON.parse(data);
return tempdata.record;
} });
};
Edit: Thanks @nicklasb
Regarding your insight Yes, you are right I think it will be great if a user can specify the type of data returned to the async callback
. It will be a great option to have. Gladly $http resolves it with transformResponse
. Thanks for your time anyways.
Interesting, good find, did not know about that one.
In that case, transformResponse is actually sufficient, it is only for the asyncCallbacks that it is neccessary, I'll mention that in the documentation. Good stuff.
Added a mention of transformResponse in the docs for the develop branch, closing.
Hi All
I am using dreamfactory for my REST API backend and I am using this code to get the promise back.
controller.js
and on my form
This is the error I am getting
When I do
console.log($scope.thisfunct)
I am getting a promise back with the value as the data array. What should I do I have tried every possibility.