mercredi 30 janvier 2019

How to set checkbox ng-checked from server data using AngularJS and save the checked/unchecked back to server data?

This should be a very common problem, invoking an ng-model to parse the data into form (DOM) after which the modified checkbox's ng-checked will be translated back to data values so to be saved back on the server.

I have two check boxes respectively

<table><tbody>
        <tr>
            <td align="left">To be ignored</td><td align="left">Yes 
                <input type="checkbox" ng-model="nm_ignore" /></td>
            <td></td>
        </tr>
        <tr>
            <td align="left">To be excluded</td><td align="left">Yes 
                <input type="checkbox" ng-model="nm_exclude" /></td>
            <td></td>
        </tr>
    </tbody>
</table>

And, my data is

$scope.nm_to_ignore = _a_record._ab_ignore; // "T"
$scope.nm_to_exclude = _a_record._ab_x_style; // "F"

My objective is :
I want a straight-forward easy way (easy-to-maintain codewise, which is, angularJS ng-model) to set the checkboxes CHECKED/UNCHECKED by the data read from the server. Also, I want to be able to save the values represented by CHECKED/UNCHECKED to the data just as it came.




Aucun commentaire:

Enregistrer un commentaire