0

After trying what this question ask, I'm asking again how to retrieve data from web using AngularJS in the Ionic framework. Basically, I do what the answer says:

.factory('Advices', function($http) {
   var advices = null;
   $http.get('http://myurl.myext/myfile.json').success(function (data) {
       advices = data;
   }).error(function(error) {
       console.log('error'); //even if there i print the error it prints nothing
   });

   //etcetera

How can I rescue that file from my server?

Community
  • 1
  • 1
Lowe B
  • 79
  • 1
  • 2
  • 11

1 Answers1

1

Please try to following code

            var app = angular.module('myApp', ['ionic']);
            app.controller('mainInfoFactory', ['$scope', '$http', function($scope,$http) {
              $http.get("http://myurl.myext/myfile.json")
              .success(function (response) 
              {
                $scope.advices = response;
              })
             .error(function(data) {
                alert("ERROR");
              });
            }]);

Here myAPP and mainInfoFactory are AngularJS application name and controller respectively.

For example : ng-app="myApp" ng-controller="mainInfoFactory"

Santosh Shinde
  • 6,045
  • 7
  • 44
  • 68