0

I use this code to add a property in the filter when a checkbox is cheked.

<input ng-model="filter['model']['first']" value="first" type="checkbox" name="model">

I tried to do this in the controller, to take the stateparams value and preselect the checkbox

$scope.filter = {};
$scope.model=$stateParams.model;
if($scope.model == 'first')
{filter="['model']['first']"}
else if if($scope.type == 'second')...

But it's not working, the filter is not working and I it don't match with any element anymore.

1
  • can't set a value with only one $stateParam for something that requires both a key and a value. Does $stateParams also have a property that includes a value for the model? Commented Jul 13, 2015 at 13:15

1 Answer 1

0

Is this what you meant to have?

$scope.filter = {};
$scope.model=$stateParams.model;
if($scope.model == 'first')
{
    $scope.filter="['model']['first']"
}
else if($scope.type == 'second'){
    ...
}

If so your problem is this:

$scope.filter = {};
$scope.model=$stateParams.model;
if($scope.model == 'first')
{
    $scope.filter['model'] = {};
    $scope.filter['model']['first'] = ???;
}
else if($scope.type == 'second'){
    ...
}

I'm not sure what you're trying to set your ['model']['first'] too.

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

2 Comments

$scope.filter="['model']['first']" as a string makes no sense
I know, that's why my solution does not include it.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.