1 min readMay 16, 2020
A nice example of polymorphism in Angular! You could also get rid of the if
statements entirely and use a switch
statement.
Or if such trivial functionality doesn’t warrant creating multiple sub-class services, I like to use a Map
and keep it all in one Service.
public typeColors<Map<string, string>> = new Map<string, string>([
['math', 'red'],
['eng', 'blue'] ...
getColor(type: string): string { return this.typeColors.get(type);}