Having some troubles reversing the checkbox value in Angular 2.
In Angular 1.x we could make a directive like below.
.directive('invertValue', function() {
return {
require: 'ngModel',
link: function(scope, element, attrs, ngModel) {
ngModel.$parsers.unshift(function(val) { return !val; });
ngModel.$formatters.unshift(function(val) { return !val; });
}
};
})
why you need directive for this simple thing
you can achieve like this
<input type="checkbox" [checked]="!value" (change)="value= !value" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With