Skip to content Skip to sidebar Skip to footer

Angularjs Get Filtered Input From Ng-repeat To A Javascript Variable?

I'm currently working with AngularJs and am filtering an input array with a number of select boxes. On the filtered result, I'm running an ng-repeat to display each element in my n

Solution 1:

You can directly store the array in your ng-repeat

<ul ng-repeat="sq in (filteredInput = (input| filter:languageModel| filter:nameModel))>

Now you can access $scope.filteredInput to get the filtered array

Solution 2:

You can call the filter directly from javascript:

$scope.filteredInput = $filter('languageModel')($scope.input);

Where languageModel is the name of your filter. Make sure to inject $filter in your controller.

By the way, it is weird to have the ng-repeat on the <ul> element. Something more appropriate would be to put it on the <li>:

<ul><ling-repeat="sq in input| filter:languageModel| filter:nameModel>
        <span>Language: {{sq['Language']}}</span>
        <span>Name: {{sq['Name']}}</span>
    <li>
</ul>

Solution 3:

You can write your own filter function in your code behind, something like this

$scope.filterlanguage=function(item){

//add your condition if satisfies return or nullif(condition)
{
return item;
}
returnnull;


}

Post a Comment for "Angularjs Get Filtered Input From Ng-repeat To A Javascript Variable?"