0

All I want to filter some values with in ng-repeat, I have tried but haven't got a solution...

  • My Plunker.

  • I am looking for three kinds of solution,

(i) In my plunker first, i am looking to filter ng-module="request_role" value of parent in the list. so I had tried like | filter: request_role.[parent'].

(ii) In my plunker second list, i am looking to filter ng-module="request_role" value of Change Agent. so I had tried like | filter: request_role.['Change Agentent'].

(i) In my plunker third list, i am looking to filter ng-module="request_role" value of parent,Change Agent. so I had tried like | filter: request_role.['parent,Change Agent'].

  • I think I have done a mistake in filter, so please check and update my plunker as well to know exact solution, thanks...

My Html:-

<p style="background: black;color:white">1.Filter request_role  value of `parent` data's in below list</p>
        <div  ng-repeat="question in users | filter: request_role.['parent']">
            <small>
              <table border="0">
                <tbody>
                  <th>{{question.displayName}}</th>
                <th style="background: yellow;">,{{question.roles[0]}}</th>
                <th style="background: light;">,{{question.request_role[0]}}</th>

                </tbody>
                      </table>


              </small>
        </div>

        <p style="background: black;color:white">2. Filter request_role  value of `Change Agent ` data's in below list</p>
        <div  ng-repeat="question in users | filter: request_role.['Change Agent']">
            <small>
              <table border="0">
                <tbody>
                  <th>{{question.displayName}}</th>
                <th style="background: yellow;">,{{question.roles[0]}}</th>
                <th style="background: light;">,{{question.request_role[0]}}</th>

                </tbody>
                      </table>


              </small>
        </div>

         <p style="background: black;color:white">3.Filter request_role  Both value of ["parent","Change Agent"] data's in below list</p>
        <div  ng-repeat="question in users | filter: request_role.['parent,Change Agent']">
            <small>
              <table border="0">
                <tbody>
                  <th>{{question.displayName}}</th>
                <th style="background: yellow;">,{{question.roles[0]}}</th>
                <th style="background: light;">,{{question.request_role[0]}}</th>

                </tbody>
                      </table>


              </small>
        </div>

My filter:-

  1. | filter: request_role.['parent']

    2.  | filter: request_role.['Change Agent']

3. | filter: request_role.['parent,Change Agent']

1 Answer 1

0

You can solve this using a custom filter or directly by applying a filter on ng-repeat as shown below

  1. <div ng-repeat="question in users | filter: {'request_role':'parent'}">
  2. <div ng-repeat="question in users | filter: {'request_role':'Change Agent'}">
  3. <div ng-repeat="question in users | filter: {'request_role':'Change Agent','request_role':'parent'}">

Working Plunker: http://plnkr.co/edit/NY3h8BCQn4gAbJsdyiJw?p=preview

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

5 Comments

thanks for your answer, your filter is working perfectly based on values like- Change Agent, parent,` but what we expecting the filter should base on ng-module, not a value. values are not to be constant we just gave example values in plunker, so how we do filter base on ng-module request_role .... values are not constant thanks....thank you so much for your help..
I don't understand your requirement. Do you mean ng-model?
But where is your ng-model in the above plunker?
we have not mentioned ng-model in plunker, I just want to filter only this model request_role not with values...
I don't still understand your requirement. You cannot filter something based on request_role without giving values. But if you want to filter based on an ng-model like ng-model="val.request_role", then you can do something like this <div ng-repeat="question in users | filter: {'request_role': val.request_role }"> where val.request_role can be 'parent','Change Agent' etc i.e the values that request_role from your object array can contain

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.