0

I am new to angular and trying to consume a basic back end service that I created using laravel. It is a basic Todo application and I am trying to fetch all the users resource for now.

If you go to the following URI, it will give back the all the users in the application:

Link to the URI

The code in my angular file looks like

var testing = angular.module('testing', []);

testing.controller('MainCtrl', function($scope, $http){
    $scope.hello = "Hello World!";
    $http.get('users.json').success(function(data){
        $scope.users = data;
    });
});

Now when I pass the URI in the parameter of $http.get method, I don't see any data. I have tried {{ users | json }} in my main index file to see the dump output. It simply doesn't work. But when I copy just the data array in the response and save it to a json file, it works perfectly.

Now the json that is returned from the web service has slightly more information like status and messages. How do I remove them when fetching them in Angular so that it works or is there a way I can have them returned and then extract them somehow from the whole data that has been returned?

8
  • is success callback function executes ? Commented Nov 11, 2014 at 9:04
  • I think it does. Because when I am using the json file, it returns all the data. Commented Nov 11, 2014 at 9:05
  • 1
    The URL you gave us is http://todoapi.rohanchhabra.in/users. So why are you using users.json? There is no .jsonin the working URL. Commented Nov 11, 2014 at 9:06
  • users.json is a file that I created locally to check if it fetching the data without the status and messages. The users.json file only contains the data array copied from the actual response. Commented Nov 11, 2014 at 9:07
  • 1
    You should provide the actual code you try, the actual content of the file you're trying to access, and define what you mean by "doesn't work". A plunkr or jsfiddle would help. Commented Nov 11, 2014 at 9:22

1 Answer 1

1

If here http://todoapi.rohanchhabra.in/users is response from your server you should update your $http call to :

 $http.get('users.json').success(function(response){
        $scope.users = response.data;
    });

if you requesting json file from your local iis make sure that it can serve .json files

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

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.