Angularjs, How to create Checkbox to insert array in MongoDb

0

I have created a collection in mondoDB called Mangas , where it has " name, author, gender and info

Gender is array.

I have a form that will receive the values name, author and info, Checkbox needs to be filled as Array with values to be inserted with the forumulario

Question. How to make a Checkbox that has 2 options Adventure and Action and insert in mongoDB as an array?

Same as the collection below.

MongoDB Sleeves

db.mangas.insert({
    nome:'Toriko',
    autor:'não sei',
    genero:['aventura','ação'],
    info:'...'
    })

Index.html

<tr>
  <td><input class="form-control" ng-model="manga.nome"></td>
  <td><input class="form-control" ng-model="manga.autor"></td>
  <!-- aqui precisa ser a CHECKBOX que irá ter os valores do array e inseridos no GENERO -->
  <td><input class="form-control" ng-model="manga.info"></td>



  <td><button class="btn btn-primary" ng-click="addManga()">Add manga</button></td>
</tr>

     <tr ng-repeat="manga in mangas">
       <td>{{manga.nome}}</td>
       <td>{{manga.autor}}</td>
       <td><!-- aqui vai listar o valor recebido do checkbox --></td>
       <td>{{manga.info}}</td>
     </tr>

Function addManga

$scope.addManga = function() {
    console.log($scope.manga);
    $http.post('/mangas', $scope.manga).success(function(response) {
      console.log(response);
       refresh();
    })};
    
asked by anonymous 02.02.2016 / 19:50

1 answer

1

I did a basic SPA showing how you can use a function in the ng-click of each input checkbox to add or remove items from your array of genres.

This app has a difference, instead of adding strings in the list I add objects, one for each genre, so you can give them more use.

I used the style guide created by this guy to ride this SPA.

Link to Plnkr

    
05.02.2016 / 14:04