4rh4m97
4rh4m97

Reputation: 15

loading multiple JSON files in AngularJS

I have two different JSON files and they have the same attributes in them. I'm able to load them by using two promises in my service but when I go in my HTML and try to display my data they display the same thing.

This is my service:

$http.get("data.json");

            //User JSON api
            $http.get("data1.json")
                .then(function (response) {
                        dataRecievedCallback(response.data);
                    }

Should I assign my $http.get to a variable, if yes How can I do that and do I need to change anything in my controller? I haven't been coding for long and I'm new to angular so all the help is appreciated.

Upvotes: 0

Views: 802

Answers (1)

Wee Hui Pherng
Wee Hui Pherng

Reputation: 41

$http.get("data.json")
      .then(function (response) {
           $scope.foo = response.data;
       }
$http.get("data1.json")
      .then(function (response) {
           $scope.bar = response.data;
       }

Not sure about your "dataRecievedCallback()" function, if your function set the data into the same variable, the second $http call will overwrite the first one.

Upvotes: 1

Related Questions