javascriptangularjscheckboxangular-ngmodelangularjs-ng-change

Angular checkbox to filter data


I am showing FreeEvents using checkbox. I am passing the value to the filter as filter:filterFreeEvent . This is working fine.

But I want to avoid passing value in the filter rather I want to use a change event of a checkbox to filter.

Something like

  <input type="checkbox" ng-model="showFreeEvent" ng-change($event)">

This is my JsFiddle example.

Has anyone done something like this?. Any help or suggestion would be appreciated.

Thanks in advance


Solution

  • You can also change a variable in the change-event only like this :

    <input ng-model="changeValue" ng-change="showFreeEvent = showFreeEvent== false ? true : false" value="" type="checkbox" />
    

    If the showFreeEvent is false, ng-change will change it to true and vice-versa.