Eucar Eucar - 11 months ago 48
Javascript Question

Angular JS filter giving 'notArray' error

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.


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

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

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

.then(function (res) {

var s1 =[0].players;
var s2 =[1].players;

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


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

Answer Source

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

vm.players = [];