Doubt with angular and checkbox

Asked

Viewed 106 times

1

I have a form with some inputs and some checkbox, when I do the search in the database is returned Json, and input fields are filled in but checkbox are not marked although I have declared the ng-model of it:

 <p>
     <input type="checkbox" name="t0080_pbm_testado" id="t0080_pbm_testado" icheck ng-model="checklist.t0080_pbm_testado" />
     <label for="checkbox_demo_1" class="inline-label">Teste</label>
 </p>

What’s wrong with it?

View excerpt

  <div class="uk-form-row">
    class="uk-grid">
       <p>
          <input type="checkbox" name="t0080_pbm_instalado" id="t0080_pbm_instalado" icheck ng-model="checklist.t0080_pbm_instalado" />
          <label for="checkbox_demo_1" class="inline-label">Instalação</label>
      </p>
      <p>
        <input type="checkbox" name="t0080_pbm_configurado" id="t0080_pbm_configurado" icheck ng-model="checklist.t0080_pbm_configurado" />
        <label for="checkbox_demo_1" class="inline-label">Configuração</label>
      </p>
      <p>
        <input type="checkbox" name="t0080_pbm_testado" id="t0080_pbm_testado" icheck ng-model="checklist.t0080_pbm_testado" />
        <label for="checkbox_demo_1" class="inline-label">Teste</label>
      </p>
       <p>
         <input type="checkbox" name="t0080_pbm_treinado" id="t0080_pbm_treinado" icheck ng-model="checklist.t0080_pbm_treinado" />
         <label for="checkbox_demo_1" class="inline-label">Treinamento</label>
      </p>
  </div>
 </div>

angular controller method

 $scope.checklist = {};
$scope.getCheckList = function () {      
        var url = "http://localhost:23714/CheckList/getCheckList?idEmpresa=1&user=a&pass=1";

    $http.get(url).success(function (data) {
        $scope.checklist = data;
    })
};

** inputs are normally filled, checkbox not

  • Post the code that tries to mark the checkbox please. Use the edit button.

  • As you are setando checklist.t0080_pbm_testado?

  • Ah, and how is Json returning from its API?

  • Thiago Lunardi, I edited the post and put the codes there, thanks for while

1 answer

1

In the example below the element t0080_pbm_testado is correctly marked as checked via Dirty checking Angular after 3 seconds:

function SampleController($scope, $timeout) {

  $timeout(function() {
    $scope.checklist = {t0080_pbm_testado: true}

  }, 3000);

}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<body ng-app>
    <div ng-controller="SampleController">
      <p>
        <input type="checkbox" name="t0080_pbm_testado" id="t0080_pbm_testado" icheck ng-model="checklist.t0080_pbm_testado"/>
        <label for="checkbox_demo_1" class="inline-label">Teste</label>
      </p>      
      
      {{checklist | json }}
      
    </div>
  </body>

Your error may be happening due to object update failure $scope.checklist, or because its population is occurring outside the cycle of Digest angular.

Browser other questions tagged

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