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.

user567
  • 3,712
  • 9
  • 47
  • 80
  • 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`? – charlietfl Jul 13 '15 at 13:15

1 Answers1

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.

Mathew Berg
  • 28,625
  • 11
  • 69
  • 90