Angular, ngModel: checkbox is checked, but the value is set to "false"

37 Views Asked by At

I have issue with angular ngModel checkbox. I integrate angular with mySql database, and backend in spring. I wanted to add checkbox to edit if pizza is vegan or not. I use ngModel to get values from db, but because of using ngModel checkbox is always set to checked.

<!-- Edit Pizza Modal -->
<div class="modal fade" id="updatePizzaModal" tabindex="-1" role="dialog" aria-labelledby="pizzaEditModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
     <div class="modal-content">
        <div class="modal-header">
           <h5 class="modal-title" id="updatePizzaModalLabel">Edit Pizza {{editPizza?.name}}</h5>
           <button type="button" class="close" data-dismiss="modal" aria-label="Close">
           <span aria-hidden="true">&times;</span>
           </button>
        </div>
        <div class="modal-body">
           <form #editForm="ngForm">
              <div class="form-group">


           <div class="form-group">
                 <label for="vegan">Vegan?</label>
                 <input type="checkbox" ngModel="{{editPizza?.vegan}}" name="vegan" class="largerCheckbox" id="vegan">
              </div>


              <div class="modal-footer">
                 <button type="button" id="" data-dismiss="modal" class="btn btn-secondary">Close</button>
                 <button (click)="onUpdatePizza(editForm.value)" data-dismiss="modal" class="btn btn-primary" >Save changes</button>
              </div>
           </form>
        </div>
     </div>
  </div>
</div>

Any ideas how I could make it depend on the value in the database (in db is "true" or "false").

0

There are 0 best solutions below