基本上它很简单,但我无法使其发挥作用。
注意:使用离子。
我有:
预定义播放列表的视图和控制器
UserPlaylists的视图和控制器。
用于将歌曲分配给UserPlaylist的离子弹出窗口。
它应该像这样工作: 我查看预定义播放列表中的歌曲。我选择要添加到UserPlaylist的歌曲。弹出窗口出现,允许选择UserPlaylist来添加歌曲。我选择它并将歌曲添加到UserPlaylist。该应用在预定义的播放列表视图中仍然 。
一切正常。 当我使用新歌切换回用户播放列表时,用户播放列表的视图不会更新 - 我需要RELOAD UserPlaylist视图,然后我可以看到添加了新歌...
我无法使用$ apply(),它是否会告诉我它已经在进行中。离子或角度是以某种方式缓存的吗?
播放列表html
<div ng-hide="loading">
<h2>{{playlist.name}}
<button on-tap="addAllToUserPlaylist()" class="small add-to-playlist"></button>
<button on-tap="addAllToQueue()" class="small add-to-queue"></button>
<button on-tap="playAll()" class="small play"></button>
</h2>
<app-song can-like="true" can-add-to-queue="true" can-add-to-playlist="true" on-select="tappedSong(song)" item="song" ng-repeat="song in playlist.songs" />
</div>
</ion-content>
歌曲指令
中添加播放列表代码/**
* AddToPlaylist button was tapped
*/
function addToPlaylist(e){
e.stopPropagation();
// Show add to playlist template as a popover.
// Note that we're passing this directive's scope
// as the popover's parent scope. That way the popover's
// controller will have access to the variables here.
// Also, we're putting a reference to the popover in
// scope.popover so we can access it later to destroy it.
$ionicPopover.fromTemplateUrl('templates/add.to.playlist.html',{
animation: 'slide-in-up',
scope: scope,
backdropClickToClose: false
}).then(function(popover){
scope.popover = popover;
popover.show();
});
}
UserPlaylist代码:
UserPlaylistDataSource.prototype.addSongs = function(songs, id, beginning, cbk){
if(beginning){
Array.prototype.unshift.apply(this.songs, songs);
}
else{
Array.prototype.push.apply(this.songs, songs);
}
this.save(id, cbk);
}
popover添加代码:
$scope.add = function(playlist){
var toAdd;
var msg = 'Agregaste $1 a la lista ' + playlist.name;
// If the parent scope has an 'item' it is the song they want to add
if($scope.item){
toAdd = [$scope.item];
msg = msg.replace('$1', 'una canción');
}
// If the parent scope has a 'playlist' add all of it's songs
else if($scope.playlist){
toAdd = $scope.playlist.songs;
msg = msg.replace('$1', $scope.playlist.songs.length+' canciones');
}
// If the parent scope has a 'queue' add all of it's songs
else if($scope.queue){
toAdd = $scope.queue.songs;
msg = msg.replace('$1', $scope.queue.songs.length+' canciones');
}
$scope.loading = true;
playlist.addSongs(toAdd, playlist.id, false, function(err){
$scope.loading = false;
//HERE playlist has the correct number of songs! So it worked!
if($scope.item) $scope.unflip(); // if parent scope is a single song.
$scope.close();
if (err) {
return MessageService.show(err);
}
MessageService.show(msg);
});
};
popover html:
<ion-scroll>
<h3 on-tap="newPlaylist()"><img src="/img/icon-round-add.png"/> <span>Crear Nueva Lista de Reproducción</h3>
<div class="spinner-container" ng-show="loading"><ion-spinner></ion-spinner></div>
<br/>
<h3 class="playlist" ng-repeat="playlist in playlists" on-tap="add(playlist)"><img ng-src="{{playlist.client_data.icon_url}}"/> <span>{{playlist.name}}</span></h3>
</ion-scroll>
答案 0 :(得分:1)