0
I created a collection on mondoDB called Sleeves, where you have "name, author, genre and info"
Gender is array.
I have a form that will receive the values name, author and info, the Checkbox must 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 into mongoDB as array?
Like the collection below.
Mongodb Mangas
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>
AddManga function
$scope.addManga = function() {
console.log($scope.manga);
$http.post('/mangas', $scope.manga).success(function(response) {
console.log(response);
refresh();
})};
Just to make sure I understand: your question is about how to create a list of checkboxes linked to an array in your scope, this?
– Juan Biscaia
That’s right, why do that? no gender, would be an array, checkboxex would have 2 options example:"Action", "Adventure", in the form, selects the 2 options of checkboxes and sends as array to mongoDB, so would create a generic table and look for all values of Action and Adventure.
– Braian Silva
@Juanbiscaia I don’t know how to create a checkbox with the values of the array and how to create a function to send the value of the checkboxes.
– Braian Silva