What is the best way to determine the length of filtered questions in AngularJS?

How do I retrieve the length of filtered questions in AngularJS?

  • Link to My Plunker

  • I am attempting to get the length of the filtered questions by using

    Total no of questions:{{question.length}}
    , but it is displaying the total number of questions overall, for example: 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.

Answer №1

Revise the question length coding as shown below:

 <p class="color">Total number of questions: {{((question) | filter:{status: 'pending'}).length}} </p>

Link to functioning plunkar code

Answer №2

To display the total number of questions from the filtered data, you can use {{resultValue.length}}

<p class="color">Total number of questions: {{resultValue.length}} </p>

See a working example on Plunker: http://plnkr.co/edit/IiI1L6JjnWorIQCaWWIU?p=preview

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The grid elements are not in perfect alignment

I'm having trouble aligning the <p> element to the left and the image to the right. The image is not aligning properly with the fourth column, so I need to figure out how to fix that. .content{ display: grid; grid-template-columns: 25% 25 ...

What could be causing the text in the sidenav to vanish when the screen width reaches a specific size?

Disclaimer: This website is my first attempt at development, so I tend to make minor errors that can be hard to catch. The sidebar and submit button remain intact, but the checkboxes and their labels disappear when the screen size is reduced below a certai ...

The CSS cursor style is taking precedence over the inline cursor style while dragging items in the list

I am currently utilizing the Nestable JS library and have a list of nestable items in my tree. I am trying to implement a cursor: pointer when hovering over them and a cursor: move when dragging. However, I am facing issues in getting this functionality to ...

I am looking to incorporate a feature in my form that allows for multiple file uploads and displaying them

Currently, I have a single file upload input field in my form and it works perfectly fine. However, I am looking to add multiple file inputs to the form as well. I have attempted various methods to integrate the code for multiple file uploads into my form, ...

concealing a footer behind the main content by utilizing z-index

My goal is to conceal a footer beneath the main content that will only become visible when the main content is scrolled above the footer itself. However, I am encountering an issue where setting the footer's z-index to a negative value successfully hi ...

AngularJS enables tab highlighting by responding to button selections

In my application, there are 3 tabs set up as follows: <li ng-class="{ active: isActive('#one')}"><a data-toggle="tab" class="tab-txt-color" href="#one" ng-click="selectTab('fruits') ...

I'm looking for a library or plugin that can be used to develop a customizable sidebar window with docking, resizing, and pinning capabilities similar to the ones found

In Visual Studio, the solution explorer and toolbox windows can be hidden at the side unless pinned. They are also resizable. Is there a way to achieve this same behavior using CSS? Has anyone created a jQuery plugin or similar tool for this? ...

What is the best way to extract checkboxes values using jQuery?

In order to retrieve the value of a checkbox using jQuery, I am working with an ng-model from AngularJS. My objective is to determine whether the checkbox is true or false, and based on that result, apply a bootstrap collapse class. ...

The validation process is still failing even though the correct credentials have been entered

I'm diving into the world of Javascript and DOM today, but I've hit a roadblock. Can you take a look at this code snippet and help me figure out what's causing me to always end up in the else block, no matter what I input in the text field? ...

Custom authentication in ASP.NET Web API involves creating custom authentication mechanisms to

My Web Api provides basic information about a company, and in order to access it, users simply need to provide a username and a password. The login details are validated against a database for a Desktop App. However, I am looking to implement an authentica ...

Guide for finding the current font of an HTML element

Imagine having a text element styled as follows: font-family: Arial, Verdana, Sans-serif; Is there a way to determine which specific font (Arial, Verdana, or Sans-serif) the browser utilized to display the text? ...

The element selector is taking precedence over my class selector

Currently tackling a project for my university course and facing an issue with this section of my html+css code: h1, h2, h3 { color: #747d19; } .name_date { color: #861781; } <div class="name_date"> <h3>Shean</h3> &l ...

Show a collection of items surrounding an image in order to form a circular menu

For my website, I'm looking to implement a circular navbar that will surround the user avatar. Using ul and li elements, I have created various options that are necessary. Is there a way to position all the navItems around the bottom half of the avata ...

initiate changes to the application's style from a component nested within the app

I'm looking to update the background color of the entire page, including the app-nav-bar, when I'm inside a child component. When I navigate away from that component, I want the default style to be restored. Any suggestions on how to achieve this ...

ngTransclude not encompassing any content whatsoever

I am facing an issue with a custom Angular directive that is used in several of my AngularJS views. The directive is set to transclude, but the wrapped content is not appearing. app.directive('card', [function() { return { restrict: "E", ...

The native javascript modal fails to appear

I'm attempting to implement the functionality from this Codepen demo into my project. I've copied over the HTML, CSS, and JavaScript code: <!DOCTYPE HTML> <html> <head> <script> var dialog = docume ...

Creating a stylish dotted line separator or infill using CSS

I am currently working on developing a restaurant's website. I have been tasked with incorporating a dotted line infill between each menu item and its corresponding price. Despite spending a considerable amount of time searching online and testing dif ...

When working with AngularJS, you can enhance your application by implementing a global AJAX error handler if one has

Is there a way to set a global AJAX handler that will only be called if an error handler is not already defined for a specific AJAX call? Some of my AJAX calls need to execute certain logic if an error occurs (such as re-enabling a button), while others s ...

the division does not span the entire width

I am faced with a dilemma involving two div elements structured as follows: <div id="left"><p>.....</p><br/> <p>.....</p> </div> <div id="right"><img ..../></div> Accompanied by CSS styling: #l ...

Steps for inserting an item into a div container

I've been attempting to create a website that randomly selects elements from input fields. Since I don't have a set number of inputs, I wanted to include a button that could generate inputs automatically. However, I am encountering an issue where ...