当我使用 Angular 的 ng-options 时,我得到了这个奇怪的错误:
Error: [ngOptions:iexp] Expected expression in form of '_select_ (as _label_)? for (_key_,)?_value_ in _collection_' but got 'playlist.id as playlist.name in playlists | orderBy: 'playlist''. Element: <select class="ng-pristine ng-valid" name="playlist" ng-model="playlist" ng-options="playlist.id as playlist.name in playlists | orderBy: 'playlist'">
我的代码是:
<select name="playlist" ng-model="playlist" ng-options="playlist.id as playlist.name in playlists | orderBy: 'playlist'"></select>
<button class="btn btn-branded" ng-click="postSongToPlaylist(playlist.id);">Save</button>
ng-model 指的是这个文件:
MediaService.getPlaylists().then(function (response) {
$scope.playlists = response.data.data;
});
$scope.postSongToPlaylist = function(playlist_id) {
media = {
id: $rootScope.song_id
};
MediaService.postSongToPlaylist(playlist_id, media).then(function (response) {});
}