mercredi 29 juin 2016

Reverse checkbox value

I am running an angular ionic application and am having trouble reversing the value of my checkbox. I have tried the various options listed on this link (AngularJS: Reverse Checkbox State) to no avail.

I have created a directive as follows and implemented it into my checkbox as such:

<ion-checkbox negate ng-model="vm.filter.hide">
     
</ion-checkbox>


// negate.directive.js
angular
    .module('app.directory')
    .directive('negate', negate);

function negate() {
    return {
        require: 'ngModel',
        link: function(scope, element, attribute, ngModel) {
            ngModel.$isEmpty = function(value) {
                return !!value;
            };
            ngModel.$parsers.unshift(formatter)
            ngModel.$formatters.unshift(formatter);

            function formatter(value) {
                return !value;
            }          
        }
    };
}

Any insight on what might be the problem is welcome. Thanks




Aucun commentaire:

Enregistrer un commentaire