How do I retrieve the length of filtered questions
in AngularJS?
I am attempting to get the length of the filtered questions by using
, but it is displaying the total number of questions overall, for example:Total no of questions:{{question.length}}
4
.When a filter like this is applied:
| filter:{status: 'pending'}
, only 2 data entries are visible on the table. In this case, I want to display the length of these filtered questions and expect an answer like this:2
Please refer to my plunker for more details Link to My Plunker.
HTML Code:
<tr ng-repeat="mani in resultValue=((question) | filter:{status: 'pending'}) ">
<td>{{$index + 1}}</td>
<td>{{mani.title}}</td>
<td>{{mani.upvotes }}</td>
<td>{{question.length}}</td>
</tr>
<tr>
<td>sum</td>
<td></td>
<td>{{resultValue | sumOfValue:'upvotes'}}</td>
<td></td>
</tr>
</table>
<p class="color">Total no of questions :{{question.length}} </p>
<p>Total no of upvotes : {{resultValue | sumOfValue:'upvotes'}}</p>
<p>Total no of Open Eyes of [1 values] : {{resultValue | sumOfValue:'openeyes'}}</p>
<p>Total no of Open Eyes of [0 value] : {{resultValue | sumOfZeros:'openeyes'}}</p>
Filter Used :-
filter:{status: 'pending'})
Data Set:-
$scope.question = [
{
"_id": "5936a70095e3a85804aae050",
"user": {
"_id": "58072aba0f82a61823c434df",
"displayName": "Table 1",
"roles": [
"admin"
],
"profileImageURL": "./modules/users/client/img/ownprofile/uploads/1f08308f43b0674d61a2cc5d95deb5ef",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a0cdd3e0c59291c4c5d3c9c7ced38ec3cfcd">[email protected]</a>",
"categories": []
},
"__v": 1,
"status": "pending",
"openeyers": ["<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cfbcaebdaeb8aea1ae8fa8a2aea6a3e1aca0a2">[email protected]</a>"],
"openeyes": 1,
"upvoters": [
"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="304351425147515e5170575d5759fe5458595b">[email protected]</a>"
],
"upvotes": 1,
"title": "what is cricket",
"created": "2017-06-06T12:58:40.204Z"
},
{
"_id": "5979a913c999e9302caece15",
"user": {
"_id": "58072aba0f82a61823c434df",
"displayName": "karthi",
"roles": [
"admin"
],
"profileImageURL": "./modules/users/client/img/ownprofile/uploads/1f08308f43b0674d61a2cc5d95deb5ef",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="93f8f2e1e7fbfad3f6a1a2f7f6e0faf4fde0bdfd81f5f9fd">[email protected]</a>",
"categories": []
},
"__v": 1,
"status": "approved",
"openeyers": [],
"openeyes": 0,
"upvoters": [
"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="36455744574157585776515b575f5a1855595b">[email protected]</a>"
],
"upvotes": 1,
"title": "who fan you are",
"created": "2017-06-06T12:58:40.204Z"
},
{
"_id": "5936a70095e3a85804aae050",
"user": {
"_id": "58072aba0f82a61823c434df",
"displayName": "Table 1",
"roles": [
"admin"
],
"profileImageURL": "./modules/users/client/img/ownprofile/uploads/1f08308f43b0674d61a2cc5d95deb5ef",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="553e3427213d3c15302425212423332729253077333e343b1b262834">[email protected]</a>",
"categories": []
},
"__v": 1,
"status": "pending",
"openeyers": [],
"openeyes": 0,
"upvoters": [
"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="214c526144131045444248464f520f424e4c">[email protected]</a>",
"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a1d7d1e1c6ccc0c8cd8fc2cecc">[email protected]</a>"
],
"upvotes": 2,
"title": "best of the day",
"created": "2017-06-06T12:58:40.204Z"
},
{
"_id": "5979a913c999e9302caece15",
"user": {
"_id": "58072aba0f82a61823c434df",
"displayName": "karthi",
"roles": [
"admin"
],
"profileImageURL": "./modules/users/client/img/ownprofile/uploads/1f08308f43b0674d61a2cc5d95deb5ef",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="caa7b98aaff8fbaeafb9a3ada4b9e4a9a5a7">[email protected]</a>",
"categories": []
},
"__v": 1,
"status": "approved",
"openeyers": ["<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d8b5ab98bdeae9bcbdabb1bfb6abf6bbb7b5">[email protected]</a>"],
"openeyes": 1,
"upvoters": [
"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="90fde3d0f5a2a1f4f5e3f9f7fee3bef3fffd">[email protected]</a>",
"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b3c5c3f3d4ded2daf99bdccfdbdcfdcdecdbcbffcddcac">[email protected]</a>",
"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4f223c0f28222e26454a4a270e15180329425548">[email protected]</a>"
],
"upvotes": 0,
"title": "he is best",
"created": "2017-06-06T12:58:40.204Z"
},
]
- The expected total number of questions should be:
2
. Kindly review my plunker and provide the updated solution. Thank you.