0
我正在使用twitch api製作一個Angular App。在異步ajax調用之後,我必須做些什麼來刷新重複範圍($ scope.players)?刷新ng範圍爲ng repeat
app.controller('MainCtrl', function($scope,TwitchFactory) {
$scope.channels = channels;
$scope.players = [];
handlePlayers();
function handlePlayers() {
var player;
var length = channels.length;
for (var i = 0; i < length; ++i) {
switch (channels[i].serviceId) {
case '3':
TwitchFactory.getPlayer(channels[i]).done(function(data) {
if(data.stream) {
player = {};
player.game = data.stream.game;
$scope.players.push(player);
}
});
break;
}
}
}
});
謝謝。他沒有更新模型的原因? – YYY
'$ apply'有幫助嗎? –
是的。這有幫助。 – YYY