mardi 27 décembre 2016

check/uncheck the check box only if the confirmation message is true in angular js

I am new in angular js. I have a check box when i click on that checkbox a confirmation message will appear. I need to to check or uncheck the check box only if i confirm the confirmation message. How can i do it with angular js.(currently the check box is check/uncheck even if i cancel the confirmation message). This is my check box element.

<input type="checkbox" ng-init="checkValue = x.status" ng-model="checkValue" ng-true-value="1" ng-false-value="0" ng-checked="x.status == 1" ng-click="changeStatus(<% x.id %>, 1, checkValue)">

And this is my js part

var confrm          = confirm('Are you sure that you want to do this');
    if (confrm) {
        Data.post('url', param)
        .then(function(data){
            if (data.success == 1)
                AlertService.setSuccess('Status changed successfully!');
            else 
                AlertService.setError('Some error occured. Please try again');
        })
    }




Aucun commentaire:

Enregistrer un commentaire