Calling wcf in factory?


Hello so i’m new and trying to call Web service to get data. Got some problem and don’t know why could someone review this?


Hey @Endiss,

I’ve updated your codepen to do what you want!


The angular $http object works with promises, and the requests are asynchronous. You cannot therefor return the value directly, because it is not available at the time of calling the function. By using a callback method like in my example, you are able to delay processing of the data untill the moment the data is actually fetched by the $http call.

Hope you’ll see what I mean when looking at the codepen :wink:


Thank you :slight_smile: I understand now … Cheers!


@iwantwin 1 more question How to tell him to use Content-Type JSON?


What exactly do you want to tell to use conten-type JSON?

I don’t think I get it :wink: Angular $http.get will use json just as in your example (reference)

Also the API call you provided had correct headers: Content-Type:application/json


@iwantwin just one last quick question how to use params in that codepen that you reviewed?


What kind of params do you mean?

EDIT: you might have some use from this topic: How do I obtain $stateParams in Angular sevice


My Url is WCF/LoginUser?user={userName}&pass={password}
so need to pass this to WCF and thinking is there any call in IONIC to pass them or i need to build URL with this ?


Something like this would work:


Thank you :slight_smile: Hope this post will help other people too:)