I have a data structure like this:
$scope.classes = [
{Dept:'Science', Class:'101'},
{Dept:'Science', Class:'102'},
{Dept:'Science', Class:'103'},
{Dept:'Arts', Class:'111'},
{Dept:'Arts', Class:'112'},
{Dept:'Arts', Class:'113'}];
$scope.professors = [
{Dept:'Science', Class:null, Name:'John Smith'},
{Dept:'Science', Class:'101', Name:'Eric Doe'},
{Dept:'Arts', Class:null, Name:'Mary Smith'},
{Dept:'Arts', Class:'111', Name:'Frank Moore'}
]
I want to show the professor's name when the Dept and Class both match. If not, show the professor's name for that Dept (with Class=null).
However, my result looks like this:
Dept:Science Dept:Science Dept:Science Dept:Arts Dept:Arts Dept:Arts
Class:101 Class:102 Class:103 Class:111 Class:112 Class:113
John Smith John Smith John Smith Mary Smith Mary Smith Mary Smith
Eric Doe Frank Moore
How do I make the result look like:
Dept:Science Dept:Science Dept:Science Dept:Arts Dept:Arts Dept:Arts
Class:101 Class:102 Class:103 Class:111 Class:112 Class:113
Eric Doe John Smith John Smith Frank Moore Mary Smith Mary Smith
Here's my fiddle
<div ng-if="prof.Class === null && !$scope.hasProfessor(class)
, where$scope.hasProfessor(class)
searches$scope.professors
to see the class already has a professor associated with it. This would be faster if you could add another property to$scope.classes.class
,hasProfessor
, and set that totrue
when the firstng-if
triggers. Then instead of a function you could do<div ng-if="prof.Class === null && !class.hasProfessor