0

I'm trying to solve an issue where a two-way data-binding exists between a query being called with a parameter and that parameter dynamically changing with an input checkbox, but the query itself is not changing.

From the view:

<input type='checkbox' ng-model='checkbox' />

From the controller:

$scope.checkbox = false
$scope.items = Item.query({someKey: $scope.checkbox});

When checkbox is true, a small number of items are listed.
When checkbox is false, a large number of items are listed.

The checkbox can be toggled true and false, but it seems that it doesn't have an effect on the query.
Has someone ran into this issue before?

1 Answer 1

2

You need to re-run the query each time the checkbox changes. Take a look at ngChange.

Something like:

<input type='checkbox' ng-model='checkbox' ng-change="requery()" />

$scope.requery = function(){ 
   $scope.items = Item.query({someKey: $scope.checkbox});
};

That may not be exactly right--usually you set your value ($scope.items) in the success method of an ajax call (I assume that's what Item.query does).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.