I'm getting data from my local PHP file as JSON format (here's a screenshot).
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>
您应该将播放器初始化为数组而不是对象:
vm.players = [];
This is an object:
vm.players = {};
You can insert only Object
in above variable, not an array
of Object
. To insert an array
of Object
s, you need:
vm.players = [];
I think you should define your array like this:
vm.loading = true;
vm.players = [];
Not with curly brackets.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.