angularjs

Advanced filtering with AngularJS


I'm looking to filter the following list with AngularJS by both category and location. The difficulty I'm having is being able to properly nest the results beneath their respective categories (see below) after the filtering has occurred.

var jobs = [
    {
        title: "Software Engineer",
        category: "Engineering",
        location: "New York"
    },
    {
        title: "Web Developer",
        category: "Engineering",
        location: "Chicago"
    },
    {
        title: "UX Designer",
        category: "Design",
        location: "New York"
    }
]

This is the desired output (also note the alphabetically ordered categories):

Design
UX Designer

Engineering
Software Engineer
Web Developer

Any help would be much appreciated. Thanks!


Solution

  • Here is a working example with your data on plnkr using the filter solution from AngularJS Group By Directive without External Dependencies:

    http://plnkr.co/edit/w5UJUN?p=preview