Mount check box with 1 and 0 angular values

0

I have a screen that has 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 flagActive: 1 and obviously 0 when pertinent. The issue is that it does not mount on the screen .. it always comes unchecked the component, regardless if or 1.

I have a function that transforms true and or 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
    
asked by anonymous 17.01.2018 / 00:49

1 answer

1

When you make this request by GET to get the checkbox value inside the request's calback function, you have to set the value for the field. The onchange event is only called when the user changes the value of the checkbox field.

  

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

    
17.01.2018 / 01:32