Reputation: 489
I am still fairly new to angular so I was wondering how to best do something like this:
I have a json file that returns a variety of items of type 'course' and type 'tutorial'. Tutorials are related to courses with a field
data = [
{ title: foo1, type: course, id:1},
{ title: foo2, type: course, id:2},
{ title: foo3, type: course, id:3},
{ title: t1, type: tutorial, id:4, related_course:2},
{ title: t2, type: tutorial, id:5, related_course:2},
{ title: t3, type: tutorial, id:6, related_course:3},
...
In my controller I have functions bound to $scope
to allow me to filter by type.
Now in my template
<div ng-repeat="item in data | filter:isCourse">
... display course data
<div ng-repeat="item in data | filter.isTutorial">
... display tutorial data
I would like to find a way to make sure the tutorials displayed match the id of the currently displayed course.
Any suggestions?
Thanks! - V
Upvotes: 1
Views: 80
Reputation: 136144
You should have then be specific with filters
, but do make sure that JSON should be in correct format, as I can see most of the values are not there wrap in "
(double quotes)
HTML
<div ng-repeat="course in data | filter: {type: 'course'}">
... display course data
<div ng-repeat="tut in data | filter: { related_course: course.id }">
... display tutorial data
Working Fiddle(Thanks @AWolf)
Upvotes: 1