angularjs - angular 1.x array push with multiple variables via html form -


i push text via html form in array. problem every tutorial habe seen explains how add 1 variable.

my array: (this mean)

$scope.titles = [{   title: 'new divide',   artist: 'linkin park',   album: 'new divide',   genre: 'rock',   cover: 'new-divide.jpg',   titlelength: '4:28',   file: 'test' }]; 

my html form:

<form ng-submit="musiccontroller.addmusic(musiccontroller.titles, musiccontroller.artist, musiccontroller.album, musiccontroller.genre, musiccontroller.titlelength, musiccontroller.cover, musiccontroller.file)">         <input ng-model="musiccontroller.title" type="text" />         <input ng-model="musiccontroller.artist" type="text" />         <input ng-model="musiccontroller.album" type="text" />         <input ng-model="musiccontroller.genre" type="text" />         <input ng-model="musiccontroller.titlelength" type="text" />         <input ng-model="musiccontroller.cover" type="text" />         <input ng-model="musiccontroller.file" type="text" />         <button type="submit" class="btn btn-primary">add</button> </form> 

you should define ng-model each of inputs object property. way grouped in 1 object won't have push each individual value:

<form ng-submit="musiccontroller.addmusic(musiccontroller.record)">         <input ng-model="musiccontroller.record.title" type="text" />         <input ng-model="musiccontroller.record.artist" type="text" />         <input ng-model="musiccontroller.record.album" type="text" />         <input ng-model="musiccontroller.record.genre" type="text" />         <input ng-model="musiccontroller.record.titlelength" type="text" />         <input ng-model="musiccontroller.record.cover" type="text" />         <input ng-model="musiccontroller.record.file" type="text" />         <button type="submit" class="btn btn-primary">add</button> </form> 

just clarify, addmusic function should following:

$scope.addmusic = function(record) {     $scope.titles.push(record); }; 

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -