Angularjs checkbox not checked at start -


i have problem make angularjs checkbox checked.

the basket[0].partdelivery come frome db 1 update() make post db

<label class="checkbox-inline">     <input type="checkbox" id="inlinecheckbox1"  class="checkbox" ng-model="basket[0].partdelivery" ng-true-value="1" ng-false-value="0" ng-change="update()">     {{basket[0].partdelivery}} </label>  <label class="checkbox-inline">     <input type="checkbox" id="inlinecheckbox1"  class="checkbox" ng-model="1" ng-true-value="1" ng-false-value="0" ng-change="update()"> </label> 

and tested in html:

<div ng-controller="basketcontroller bc" ng-init="basket={basket}; deliveryaddress={deliveryaddress}; getcheckboxes(basket[0].partdelivery)">  <input type="checkbox" id="inlinecheckbox1"  class="checkbox" ng-model="partdeliverycheck.value" ng-true-value="1" ng-false-value="0" ng-change="update()"> 

in controller:

$scope.getcheckboxes = function(partdelivery){     $scope.partdeliverycheck={value: partdelivery}; }; 

but checkbox not checked...

the ng-model double-bind variable. you've passed in 1 in first example, can't variable.

try this

index.html

<input type="checkbox" ng-model="vm.checked"> checked: {{vm.checked}} 

controller.js

app.controller('mainctrl', function() {   var vm = this;   vm.checked = true; }); 

here's plnkr: https://plnkr.co/edit/tywbtouakuu8xhfnlqqu?p=preview

you can take @ ngchecked directive https://docs.angularjs.org/api/ng/directive/ngchecked


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -