Question

Can i use filter filterexpression without ng-repeat in angularjs.

    <li><input ng-model="query" placeholder="search on players" /> &nbsp;<input ng-model="q" placeholder="search on teams" /></li>
    <li ng-repeat="(nomeTeam, squadre) in listaSquadre" >

        <div ng-init="sq = squadre|filter:{nome:query,team:q}|orderBy:['pos','nome']" class="1c">
            <pre>{{sq}}</pre>
        <strong ng-show="sq.length > 0">{{nomeTeam}}</strong>
        <ul>
            <li ng-repeat="giocatore in sq" >{{giocatore.nome}} - {{giocatore.Role}} - 
                <span  ng-switch="{{giocatore.pos}}">
                    <span ng-switch-when="1">PF</span>
                    <span ng-switch-when="2">PA</span>
                </span>

            </li>
        </ul>
        </div>
    </li>

</ul>

The above code not filtering data. I want to print the Team name, it is external to the ng-repeat, after search.If serach return data, i want to print the team name, else no.How i can i achive this with angularjs.

Was it helpful?

Solution

Can i use filter filterexpression without ng-repeat in angularjs.

From Docs:

Selects a subset of items from array and returns it as a new array.

For sure you can use filter or custom filter (with Filter postfix) into controllers. Filters like ng-repeat directive works with arrays.

In your case I would clone the array, filter it and run with ng-repeat on filtered result

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top