Utilizing Angular: Filtering Views Based on JSON Data Values

I am struggling to figure out why a basic Angular filter is not working for me in this example. Despite following the recommended format I found online, it does not seem to be functioning properly. Essentially, I just need to display information from the array where the status is marked as "completed". Below is the snippet of code I am using:

<div class="span12" id="trainingWidget" ng-controller = "trainingInfo">
      <div class="span3 pull-right">
        <h4 class="theme-color">Available Courses</h4>
        <table id="courseList">
          <thead>
            <tr>
              <th>Location</th>
              <th>Date</th>
            </tr>
          </thead>
          <tbody>
            <tr ng-repeat="item in training | limitTo : 6">
              <td>{{item.location}}</td>
              <td>{{item.date}}</td>
            </tr>

          </tbody>
        </table>
      </div>
      <div class="span3 pull-right">
        <h4 class="theme-color">Your Last Course</h4>
        <div id="courseStatus">
          <p ng-repeat="item in training | limitTo: 1 | filter: {status: completed}">Was completed on <span id="recentTrainingDate">{{item.completionDate}}</span><br />
            <span id="recentTrainingTitle">{{item.name}}</span></p>
          <p class="theme-color">STATUS</p>
          <p><i class="icon icon-ok"></i> Up To Date</p>
        </div>
      </div>
    </div>

And here is the JSON data being used:

[
    {
        "location": "Cincinnati, OH",
        "date": "Feb 18, 2016",
        "name": "ABC Certification",
        "status": "future",
        "completionDate": ""
    },
    {
        "location": "Houston, TX",
        "date": "Mar 1-3, 2016",
        "name": "123 Certification",
        "status": "future",
        "completionDate": ""
    },
    ...
]

While I don't think it's necessary, here is a snippet of the controller code:

myBirkman.controller('trainingInfo', ['$scope', '$http', '$filter', function($scope, $http, $filter) {
    $http.get('assets/js/lib/angular/trainingData.json').success(function(data) {
        $scope.training = data;
    });
}]);

The first ng-repeat is working perfectly fine, but in the second repeat, I only want to display the first array item that has "completed" as the value of the "status" property. Thank you in advance for any assistance provided.

Answer №1

'finished' must always be enclosed in quotes:

{status: 'finished'}

If not, it will look for the variable $scope.finished.

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

retrieve a subdocument from an array in MongoDB

In my MongoDB database, I have the following data structure: {doc: { array_doc:[....//many documents]} } Currently, I am working with Mongoskin in MongoDB 2.2 with Node.js 0.8. var code_doc='HSKD41814541211'; var db = mongo.db(perm+"@127.0 ...

Tips for correctly cloning a create-react-app repository and compiling it (with existing error) - (Git)

After developing on a different server, I am now looking to move my project to the live server. On the live server, I initiated the create react app using: create-react-app test Then, I navigated into the project and initialized it with git: cd test gi ...

My function won't get called when utilizing Angular

My Angular code is attempting to hide columns of a table using the function shouldHideColumn(). Despite my efforts, I am unable to bind my tags to the <th> and <td> elements. An error keeps popping up saying Can't bind to 'printerColu ...

Ways to abbreviate a URL using Next JS

While working on my Next.js application, I encountered an issue with passing an object between pages. To achieve this, I compressed my array of objects into JSON using JSON.stringify(result) on the index page and then parsed it on the second page using JSO ...

Sending a file using Angular's $http service

I am facing an issue while trying to upload a form with an image file using the angular $http function and multer in the background for receiving. I have successfully uploaded the image via a direct form submission (without angular) as shown below: <fo ...

Avoiding quotations when inserting JSON data into MySQL table

I've encountered an issue with inserting a JSON string into a table using an insert query. Here is the problematic insert query: $insert_sql = 'INSERT INTO yun_postmeta (post_id, meta_key, meta_value) VALUES (5054, "_wc_free_gift_coupon_free ...

When using Vuejs + Laravel to make an Ajax request, only the most recent information entered into the view is submitted

Can someone guide me on implementing a basic ajax request using Vue with my Laravel backend? I have a boolean field called completed in a table named courses. In the view, users can see all assigned courses and toggle their completion status by pressing a ...

Utilizing jQuery within an Angular application

I understand that the topic of jQuery and its potential issues has been covered extensively. Despite the common advice to steer clear of using jQuery, I am curious about a different approach: How can I modify the DOM within an Angular directive without r ...

The type '{}' cannot be assigned to type 'IntrinsicAttributes & FieldsProp'. This error message is unclear and difficult to understand

"The error message "Type '{}' is not assignable to type 'IntrinsicAttributes & FieldsProp'.ts(2322)" is difficult to understand. When I encountered this typeerror" import { useState } from "react"; import { Card } fr ...

What is the process for embedding JQuery within the <body> tags in Joomla 3.1?

I inserted the following code into my default.php file in Joomla 3.1. <?php JHtml::_('jquery.framework'); JFactory::getDocument()->addScript(JURI::root().'template/mytemplate/js/jquery.min.js'); ?> However, this code only pl ...

Leveraging the power of ajax to securely save information in a database with the web2py framework

Struggling with a major issue here. I have set up the following tables db.define_table('post', Field('user_email', default=auth.user.email if auth.user_id else None), Field('title', 'strin ...

Bidirectional communication between two AngularJS scopes or controllers utilizing a service

I am facing numerous situations where I require clicks or other interactions to trigger actions in a different area of the webpage (one-way communication). Now, I have encountered a need for bidirectional communication, where changes made in element A can ...

Is it possible to utilize multiple instances of 'Data' when one of them is derived from a type function?

I've been working on getting this code to compile and function properly: module Orexio.Radix where import Data.Data import Data.Map (Map) import qualified Data.Map as Map import Data.Typeable import Text.JSON.Generic class Resource a where type R ...

Can someone guide me on how to make an array filled with dates using Javascript?

I am working on developing a Javascript code that can identify all the days leading up to the current date. Here is what I have managed so far: var titleArray = [ "title1", "title2", ]; var pictureArray = today.toString(); var thumbArray = today.toString ...

Position the vertical bar directly adjacent to the form input field

Looking for assistance with creating a unique webpage layout that includes a form where the employee ID is visually separated from the rest of the content by a vertical bar extending across the entire page. However, my attempts to achieve this using a gr ...

Using Google App Script's pageToken to store attachments on Google Drive

Essentially, my goal is to save all attachments from received emails to a specific folder in Google Drive (mostly .PDF files). However, I've encountered a limitation with the search function which only allows me to retrieve up to 500 attached files. I ...

How can I make my div disappear when I click outside of it using jQuery? I am finding the solution on Stack Overflow to be confusing

Utilizing jQuery to conceal a DIV upon clicking outside of it Although I've heard positive feedback about this method, I'm uncertain about its functionality. Can someone provide an explanation? I understand that .has() identifies elements contai ...

Allow users to copy and paste on a website where this function is typically restricted

Just wanted to mention that I have very little coding knowledge, so I appreciate your patience. I'm attempting to paste something onto a site that doesn't allow it. Here is the link to the javascript they used to block it: A friend of mine recom ...

Controllers governing adult and juvenile entities

When working with two controllers, one as the parent and the other as the child. <div ng-controller="firstCtrl as first"> <div ng-controller="secondCtrl as second"></div> </div> JS: app.controller('firstCtrl', functi ...

Obtain the string value of `reader.result` from the `FileReader

Struggling to retrieve a string in a reader.onloadend but it's constantly returning my entire function. Here is the function I'm using: uploadFile() { let vm = this; var file = vm.$refs["testeLogo"].files[0]; var reade ...