0

enter image description herehi all i work with angularjs ng-repeat .i want to bind checkbox based on db value true or false.but checkbox will not check/uncheck whether db value is true?

 serverjs// app.get('/contactdetail', function (req, res) {
console.log('I received a GET request');




db.contactdetail.find (function (err,docs) {

    console.log(docs);
    res.json(docs);

});});


controller var refresh = function () {
    $http.get('/contactdetail').success(function (response) {

        console.log('I received a GET request');
        $scope.contactdetail = response;

    });


};refresh();


  <tr ng-repeat="contacts in contactdetail><span  editable-checkbox="contacts.Number" e-name="Number" e-form="rowform" onaftersave="Dhkclick(contacts._id,contacts.Number)">{{ contacts.Number|| 'empty' }}
                                    </span></tr>
jose
  • 1,044
  • 1
  • 12
  • 35

1 Answers1

1

Remove e-name and e-form attirbutes in the editable-checkbox and bind the checkbox ngmodel with data from db and it will worked. For eg:

<span editable-checkbox="contacts.Number" onaftersave="Dhkclick(contacts._id,contacts.Number)">
{{ contacts.Number|| 'empty' }}

Update

Please make sure contacts.Number is boolean, if it is a string convert it to the boolean first

angular.forEach($scope.contactdetail, function (v) {
      if (v.Number === 'true') {
         v.Number = true;
      } else if (v.Number === 'false') {
         v.Number = false;
      }
  });

Update JsFiddle Link : http://jsfiddle.net/ts3LxjLc/9/

digit
  • 4,479
  • 3
  • 24
  • 43
  • it's hard coded means works fine i get value from DB but it's won't checked kindly verify@digit – jose Mar 10 '17 at 13:02
  • It's not the checkbox issue, it's data from db issue. Please check that the value from db is a boolean and not a string. – digit Mar 10 '17 at 13:32
  • hi @digit i edit mu post now check it's contain any mistake – jose Mar 12 '17 at 05:51
  • contacts.Number is a string value. Convert it to boolean. I'll update my answer – digit Mar 12 '17 at 07:17
  • it's work's and correctly. i need when page load directly shows checkbox checked/unchecked .not show true or false – jose Mar 12 '17 at 08:38
  • Hi @jose, i think there's no options to show the checkbox directly. That's what editable-checkbox designed for. However, you can use the input type checkbox for that purpose instead of using this library. Thanks.;) – digit Mar 12 '17 at 10:19
  • http://stackoverflow.com/questions/42758399/how-to-do-html-cell-edit-in-angular-js-mean-stack-with-mongo-db @digit. – jose Mar 13 '17 at 07:35