0
我有一個角度視圖,可以在添加數據時正確綁定到範圍中的相應數據。嘗試刪除或更新此數據時,它不綁定到視圖。以下是正在觸發的功能:角度範圍數據在更新時不綁定到視圖,但在初始化時綁定
該視圖綁定了兩個數據段:$ scope.music_stream.currently_playing_track & $ scope.music_stream.queued_tracks。
所以最初當用戶添加視頻時,會調用此函數並正確顯示在視圖中。
/**
* Create an object representing the data needed for the currently playing track
* @param {Number} id
* @param {String} thumbnail
* @param {String} title
* @param {String} added_by
* @param {String} track_duration
*/
$scope.createPlayingTrack = function(id, thumbnail, title, added_by, track_duration) {
var currently_playing_track_object = {
id : id,
thumbnail : thumbnail,
title : title,
added_by : added_by,
vote_value : 0,
track_duration : '',
elapsed_time : '0:00'
};
$scope.music_stream.currently_playing_track = currently_playing_track_object;
$scope.play($scope.music_stream.currently_playing_track.id);
currently_playing_track.track_duration = player.getDuration();
}
後,當這個視頻結束時,這個函數被調用
/**
* Triggered when the player reaches the end of a video
*/
$scope.loadNextVideo = function() {
if(!jQuery.isEmptyObject($scope.music_stream.queued_tracks[0])) { // if something is in the queue
next_video = $scope.music_stream.queued_tracks.shift();
$scope.createPlayingTrack(next_video.id, '/assets/album_cover1.jpg', next_video.title, 'ah', '3:00')
}
}
時移(後CONSOLE.LOG(scope.music_stream.queued_tracks $))
,返回[](其是我想要的),但是這並沒有延續到這個觀點。
更令人困惑的部分...當再次調用createPlayingTrack()時,$ scope.music_stream.currently_playing_track中的數據是正確的(並且該函數在第一次調用期間將數據正確綁定到視圖)......但是此次調用不會更新視圖。
我相信[這個答案](http://stackoverflow.com/a/12305082/2055998)也適用於你的情況。另請參閱[AngularJS和scope。$ apply](http://jimhoskins.com/2012/12/17/angularjs-and-apply.html)瞭解更多*更新綁定*的信息。 – 2014-09-22 21:54:30
您是否試過'$ scope。$ apply()'? – TheSharpieOne 2014-09-22 21:54:33
不知道我需要$ scope.apply()在控制器本身。現在檢查出來! – 2014-09-22 21:56:09