Christopher Marshall
Christopher Marshall

Reputation: 10736

Angular.js: ng-repeat based on item in object

Basically have two ng-repeats on the page that share an Object. I want to repeat items only if they match the type data.

Mock Object

        $scope.events = [
            {
                date: "1/16/13",
                time: "11:30",
                type: "First",
                restaurant: "Quiznos",
                location: "Echo",
                cuisine: "American",
                link: "http://google.com/event?id=239292"
            },
            {
                date: "1/16/13",
                time: "1:30",
                type: "Second",
                restaurant: "Snarfs",
                location: "5th Floor",
                cuisine: "American",
                link: "http://google.com"
            }
];

Markup

        <tr ng-repeat="event in events.type " onClick="window.open('{{event.link}}','_blank');">
                <td>{{event.time}}</td>
                <td>{{event.restaurant}}</td>                   
                <td>{{event.location}}</td>
                <td>{{event.cuisine}}</td>
        </tr>

So I want two ng-repeats. on for type = First, and one for type = Second

Something like ng-repeat="event in events.type = 'First'"

Upvotes: 2

Views: 2359

Answers (1)

Ben Lesh
Ben Lesh

Reputation: 108471

You're looking for the filter filter...

<tr ng-repeat="event in events | filter:{ type: 'First'}"/>

Upvotes: 7

Related Questions