0

I'm looking to see why a very simple Angular filter isn't working for me in example. Everything I've found online points to this format but it doesnt seem to work. Basically, I just want the information for the array that contains the value "completed" as the status. Here's my code:

<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:

[
    {
        "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": ""
    },
    {
        "location": "Cincinnati, OH",
        "date": "Apr 26-28, 2016",
        "name": "Master Trainer Certification",
        "status": "future",
        "completionDate": ""
    },
    {
        "location": "Houston, TX",
        "date": "May 15-17, 2016",
        "name": "ABC Certification",
        "status": "future",
        "completionDate": ""
    },
    {
        "location": "Cincinnati, OH",
        "date": "July 12-14, 2016",
        "name": "123 Certification",
        "status": "future",
        "completionDate": ""
    },
    {
        "location": "Houston, TX",
        "date": "Sept 28-29, 2016",
        "name": "Birkman Method&reg; Certification Training",
        "status": "future",
        "completionDate": ""
    },
    {
        "location": "Houston, TX",
        "date": "Nov 9-11, 2015",
        "name": "Birkman Method&reg; Certification Training",
        "status": "completed",
        "completionDate": "July 15, 2015"
    }
]

I dont think its nessessary but here is the controller snippet:

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 works perfectly, but on the second repeat, I just want to show the first array that contains "completed" as the value of "status". Thanks in advanced for your help.

1 Answer 1

2

'completed' should be a string:

{status: 'completed'}

Otherwise it will search for $scope.completed.

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

3 Comments

Thanks but even with the single quotes, it still isn't working.
Ahh, my apologies. THis is the correct answer. My issue was that the only item that contains that value is the last one. I thought LimitTo: 1 would limit it to only items that have that value, not 1 of the total items. The first item has null for the value of completionDate.
Good to hear! I think you want to put the limitTo filter after the filter filter, then it will limit only the ones that pass the first filter (limitTo). Like this: item in training | filter: {status: 'completed'} | limitTo: 1

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.