How to connect ionic angular to mvc WebAPI



I am a bit in trouble with connecting my ionic app to WEBAPI.

do anyone has a good idea to make a good setup for this issue.

kind regards


What problem you facing , Its very easy to connect ionic app to Web API

see steps

  1. Create Web API
  2. Create Ionic Application
  3. Create Services to call Web API
  4. Create controller and Inject Services to controller
  5. Call Services on controller
  6. Get Resposne and bind into view




Hello Virender

I have made the Webapi.
But i need to see with my own eye how to connect from ionic to webapi.
If you could spare a little demo. That would be great.




.service(‘NearByService’, function ($http) {

  this.getCityList = function () {
    return $http({
      method: 'GET',
      url: ""


Get City List on Controller

.controller(‘ManualLocationController’, function($scope, $ionicPopup, $ionicLoading, $window,$stateParams,
NearByService, locationFactory) {

    NearByService.getCityList().then(function(resp) {
        if (resp !== undefined && resp !== null) {
            if ( !== undefined && !== null) {
                $scope.CityList = [];
                for (var i = 0; i <; i++) {
                    $scope.CityList.push({ ID:[i].CityID, Title:[i].CityName });
                $scope.selected= $scope.CityList[0];



Hello Virender
Thank you for your sharing and help.



Quick question.
What is the best practice to keep the URL?
I would think that in a real application it should not be hardcoded.


Hi Virender,

Hope you are well. My team is in the process of evaluating whether this is a good framework to adopt & we find it to be wonderful. However, we are wondering how we can handle CORS (Cross Origin Resource Sharing) in cases whereby we are accessing Restful APIs hosted on a different domain.
From what we understand, a native Ionic app runs on a WebView on the targeted device; as such; we are unable to figure out what origin url to allow on our WebAPI method. Hope you can help in this regard.


Ionic +Webapi is a great framework to develop a hybrid application. CORS can be handle easily in web.cofig and startup files easily.

But when you using webapi in an ionic application that means the application can install into devices. That means no origin on such situation

config.EnableCors(new EnableCorsAttribute("", "", “*”));

But in terms of security, you can use token based authentication and Identity framework.


Hi Virender,

Thanks for your prompt response. Based on your suggestion, we will spike this.


this is Rahul Jograna, and I have created the video on YouTube where you can see I have consumed the rest API in my ionic application you can see it here source code is available on my blog