Try this:
service.GetAllSensors = function () {
return $http.get('http://localhost:8080/xxxx/xx/xx')
.then(function x) { return x.data; });
};
On Thursday, 24 September 2015 08:09:12 UTC+2, Mahendra Gurav wrote:
>
> Hi,
>
> I am using REST web service which is developed in Java. Below is the
> description how that service is implemented
>
> 1. AsynContext, with Start and Complete method
>
> Which returns the data asynchronously. We checked in cURL and we are
> able to read the data as it comes.
>
> But in when we consume that web service in AngularJS we are not able to
> get data. Here we used defer and promise like below
>
> service.GetAllSensors=function(){
>
> var deferred = $q.defer();
> var promise = $http({method:'GET', url:'
> http://localhost:8080/xxxx/xx/xx'})
> .success(function (data) {
> alert("return success "+ deferred.resolve(data));
> return deferred.resolve(data);
> })
> .error(function (data) {
> alert("error" + data);
> return {"status": false};
> });
> return deferred.promise;
> };
>
>
> //Calling method
> SensorDataService.GetTest().then(function(promise) {
> alert("promise result"+ promise);
> });
>
>
> So could anybody tell me why I am not getting the data from the service
> here.
>
> Thanks,
> Mahendra
>
>
> On Monday, September 21, 2015 at 1:27:58 PM UTC+5:30, András Csányi wrote:
>>
>> Hi Mahendra,
>>
>> As Sander described there is no difference between sync or async on the
>> client side if you use Angular. Both managed by promises (Q library of
>> Angularjs). It might be an issue how to deal with promises. Please check
>> the document about Q library where you can find examples.
>>
>> https://docs.angularjs.org/api/ng/service/$q
>>
>> On 21 September 2015 at 04:43, Mahendra Gurav <[email protected]>
>> wrote:
>>
>>> Hi,
>>>
>>> I have Java REST web service, which is implemented as async. Need to
>>> call that service in my angularjs application. I am able to call normal
>>> REST service using get method, but what should I use to call async rest
>>> service. Please give me sample code or any references for that.
>>>
>>>
>>> Thanks,
>>> Mahendra
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "AngularJS" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://groups.google.com/group/angular.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> -- Csanyi Andras (Sayusi Ando) -- http://sayusi.hu --
>> http://facebook.com/andras.csanyi
>> -- ""Trust in God and keep your gunpowder dry!" - Cromwell
>>
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.