notlkk notlkk - 5 months ago 14
AngularJS Question

ng-if to Show Default Value

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

Answer

I have created a working plunker code. Find the solution

`https://plnkr.co/edit/ElaoPpqNVgQ4aZ0AwHcu?p=preview`
Comments