1

I'm getting data from my local PHP file as JSON format (here's a screenshot).

enter image description here

The filter works fine, but I'm getting this error as you can see in the pic.

core.js

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

app.controller('listController', function($http) {
var vm = this;

vm.loading = true;
vm.players = {};

$http.get("api/players.php")
    .then(function (res) {

        var s1 = res.data.servers[0].players;
        var s2 = res.data.servers[1].players;

        vm.players = s1.concat(s2);
        vm.loading = false;
        console.log(vm.players);
    });
});

index.html

<li ng-repeat="player in vm.players | filter: search">
    <a href="#">{{ player.name }}</a>
</li>

3 Answers 3

5

You should initialize players as an array and not as an object:

vm.players = [];
Sign up to request clarification or add additional context in comments.

2 Comments

You mean that's empty after the line vm.players = s1.concat(s2) ?
Could you add a fiddle?
2

This is an object:

vm.players = {};

You can insert only Object in above variable, not an array of Object. To insert an array of Objects, you need:

vm.players = [];

Comments

1

I think you should define your array like this:

vm.loading = true;
vm.players = [];

Not with curly brackets.

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.