Skip to content Skip to sidebar Skip to footer

Checkbox Unchecking Itself After Angularjs Filter Applied

This causes the same item to be added to the array - which is used for querying - potentially twice. When the modal is closed and opened again and filtering is not used, everythin

Solution 1:

entityChecked is not declared anywhere in your javascript, so each time you filter, entityChecked is reset, so you need to make the model something that the repeater will see and have access to.

<!-- entity is now in the created child scope --><divng-repeat="entity in entityArray | filter:simpleFilter"><label><inputstyle="display: inline-block; margin-top: 5px"

         <!--setthecheckedvalueonthe 'entity' itself, thenitwillberetained-->
         type="checkbox" ng-model="entity.entityChecked"

         ng-change="getEntityFromModal(entity, entityChecked)" /> <a>{{entity}}</a></label></div>

Solution 2:

Finally have an answer - the array holding my values entityArray needs to be changed into an array holding JSON values, and for each value val there must be a value checked , which is represented by ng-model - in the above case it would be passed to getEntityFromModal(entity, entity.checked).

working plnk - https://plnkr.co/edit/2ptIAdOyaIw8mGqpU7Cp?p=preview

Post a Comment for "Checkbox Unchecking Itself After Angularjs Filter Applied"