2014-10-01 60 views
0

當我推入一個新項目的數組它將它添加到最後,無論bpm是什麼。一旦我刷新頁面,一切正常。角度orderBy不重新排序陣列推

//view 
<form ng-submit="add(newSong)"> 
    <input ng-model="newSong.artist" placeholder="Artist.."> 
    <input ng-model="newSong.title" placeholder="Title.."> 
    <input ng-model="newSong.bpm" placeholder="BPM.."> 
    <input ng-model="newSong.key" placeholder="Key.."> 
    <input ng-model="newSong.year" placeholder="Year.."> 
    <button ng-show=''></button> 
</form> 

<div ng-repeat="song in songs | orderBy:'bpm'"> 
    {{song.bpm}}/{{song.artist}} - {{song.title}} 
</div> 

//controller 
$http.get('/api/songs').success(function(data) { 
    $scope.songs = data 
}) 

$scope.add = function(newSong) { 

    var song = { 
     artist: newSong.artist 
     , title: newSong.title 
     , bpm: newSong.bpm 
     , key: newSong.key 
     , year: newSong.year 
    } 

    $scope.songs.push(song) 

    $http.post('/api/songs', song).success(function(data) { 
     console.log(data) 
    }) 

} 

當我寫這plunker一切正常,我不能告訴這有什麼錯我的環境(v1.2.25)

回答

1

我的模型使用BPM一個號碼。這解決了我的問題:

var song = { 
     artist: newSong.artist 
     , title: newSong.title 
     , bpm: parseInt(newSong.bpm) 
     , key: newSong.key 
     , year: newSong.year 
    }