0

What I'm trying to make is a comparator for statusus, I made an array of names for the names of the channels that I want to compare:

var stations = [
    "BasicChannel",
    "PixelChannel",
    "GoldenChannel"
];

Now, through using a foreach loop I want to do a HTTP call with all of those statusus:

angular.forEach(stations, function(channel) {
    $http({
        method: "GET",
        url: channel + ".php"
    }).success(function(data) {
        data.name = channel;
        $scope.channels = data; 
    });
});

Now, the problem is that I have is that every time I do a HTTP call, it overrides the other ones.

Is there a way to get these in an object, or an array maybe?

Thanks.

3
  • I'm assuming $scope.channels is what you're overriding. Why not do $scope.channels[channel] = data? Commented Dec 16, 2015 at 21:11
  • Then I woudn't be able to do "ng-repeat='channel in channels'", i think Commented Dec 16, 2015 at 21:12
  • @ChongTang Make this into an answer and I'll accept it! Thanks! Commented Dec 16, 2015 at 21:23

2 Answers 2

1

You can concatenate two array in Javascript. Like this:

$scope.channels.concat(data);
Sign up to request clarification or add additional context in comments.

Comments

0

It can insert the data at top of the array.

$scope.channels.unshift(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.