javascriptangularjsangularjs-filterangularjs-model

Use filter with angularjs controller


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.


Solution

  • 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.