0

I'm writing an Ionic app to read some data from a web API I created with asp.net MVC4. The Ionic app reads the data just fine when I'm hosting it on my local machine but the angular factory does not return anything when I try to read from the web API when it is published on Azure. Is there any logical reason why this wouldn't work when it is published to Azure?

The json string is the same on both when i visit the local and azure site.

[{"ID":1,"Name":"Fireworks","Time":"2015-11-30T21:00:00","Comments":"Be there by 8:00"},
{"ID":2,"Name":"Haircut","Time":"2015-11-30T21:00:00","Comments":"Be there by 8:00"}]

Here is the code for my angular factory

.factory('EventsFactory', ['$http', function($http) {
  return $http.get('webAPI link here')
      .success(function(data) {
        return data;
      })
      .error(function(err) {
        return err;
      });
}])

Here is the code for my angular controller

.controller('EventCtrl', ['$scope', 'EventsFactory', function($scope,     EventsFactory) {
    EventsFactory.success(function(data){
        $scope.activities = data;
    });
}])

Here is the code for my view

  <div class="list card" ng-controller="EventCtrl">
      <div class="item item-divider">Upcoming Events</div>
      <div class="item item-body" ng-repeat="activity in activities">
        <div>{{activity.Name}}</div>
      </div>
  </div>
1
  • And when you look at the network tab of your browser, is the request sent correctly ? And does it return something ? Commented Jun 29, 2015 at 13:32

2 Answers 2

1

Why you add success method with Controller and factory. add success method only controller. like

.factory('EventsFactory', ['$http', function($http) { return $http.get('webAPI link here'); }])

Sign up to request clarification or add additional context in comments.

Comments

1

In your controller, you need to use then

EventsFactory().then(function(data){
                $scope.activites = data;
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.