Doubts with angular and checkbox

1

I have a form with some inputs and some checkbox, when I do the search the bank is returned Json , and the input fields are filled in because the checkboxes are not checked even though I have declared 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?

View slice

  <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>

Angled 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, checkboxes are not

    
asked by anonymous 17.06.2016 / 12:52

1 answer

1

In the example below the element t0080_pbm_testado is correctly marked as checked via dirty checking of the 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><bodyng-app><divng-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 occurring because of failure to update the $scope.checklist object, or because its population is occurring outside the digest cycle of the angle.

    
17.06.2016 / 14:44