Mount check box with values 1 and 0 angular

Asked

Viewed 163 times

0

I have a screen that there is a check box.. let’s see;

<div class="form-group col-md-9 pull-right">
              <label>Ativo:</label> 
               <label class="checkbox-inline"><input type="checkbox" ng-model="pessoa.pessoasFisicas.flagAtivo" value="" />Sim
              </label>

              </div>

I get from my api on my front the following flagAtivo:1 and obviously 0 when pertinent. The point is that it does not mount on the screen .. always comes unchecked the component, regardless of whether or 1.

I have a function that turns true and false to 1 and 0.

  $('input[type="checkbox"]').change(function () {
        this.value ^= 1;
    });

this is the method that brings the value of the flag

$http({
            method: 'GET',
            url: '/user/pessoasFisicas/'+ pes.idPessoa,
            //async: true
        }).then(function (response) {   
          $scope.pessoa.pessoasFisicas = response.data[0];
          flagAtivo:1 // resposta do método GET
  • Where is the part of the code that receives the value pertinent to the checkbox?

  • edited the question @Rafaelsalomão

  • What is the reason for the value attribute in this input? Using angular and listening to a jQuery event?

  • It is actually to transform a boolean value into a numerical value.

  • humm.. put as answer for me to give ok here and close the question.

1 answer

1


When you do this request by GET to get the checkbox value within the request’s Calback function is where you need to set the value to the field. The onchange event is only called when the user changes the value of the checkbox field.

If you want to call the onchange, you can use Jquery Trigger, this will perform all manipulators and behaviors attached to the corresponding elements for the given event type. In general lines it will simulate the onchange behavior of your checkbox as if the user had made a change.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.