1
<script>
    var myApp = angular.module('myApp', ['angular.filter']);

    myApp.controller("MyController", function ($scope) 
    {
        $scope.movies = 
        [
            { title: 'The Matrix', rating: 7.5, category: 'Action' },
            { title: 'Focus', rating: 6.9, category: 'Comedy' },
            { title: 'The Lazarus Effect', rating: 6.4, category: 'Thriller' },
            { title: 'Everly', rating: 5.0, category: 'Action' },
            { title: 'Maps to the Stars', rating: 7.5, category: 'Drama' }
        ];
    });     

</script>
<div ng-controller="MyController"> 
    <div class="searchBar">
        <input type="text" name="title" ng-model="title" placeholder="Search..." />
    </div>
    <ul class="angularList" ng-repeat="(key, value) in movies  | groupBy: 'category'">
        <h3>{{ key }} ({{ value.length }})</h3>
        <li ng-repeat="movie in value | filter:title">
            <a href="#">{{ movie.title }}</a><br />
            <div class="rating_box">
                <div class="rating" style="width:{{movie.rating*10}}%"></div>
            </div>
        </li>               
    </ul>
</div>  

I want result :

Action (2)

The Matrix

Everly

Like this The code will be perfect, only count is not perfect with group and filter. can any guys help. So main problem is placing the filter over category.

Thanks, Ajai Pandey

2 Answers 2

3

You need to store the result of the filtered list in an alias:

 <h3>{{ key }} ({{ filteredList.length }})</h3>
 <li ng-repeat="movie in value | filter:title as filteredList">

The nice part is that you can use this variable above the ng-repeat where you are filtering, as long as it is in the scope of your controller.

See fiddle

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

Comments

0

try this below code:

<tr ng-repeat="(key, value) in data">
    <td> {{key}} </td> <td> {{ value }} </td>
</tr>

check this link for the documentation on ng-repeat.

Comments

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.