In my Angular and Firebase app, users can create new discussion topics and vote on existing ones. When a user is logged in, their username is stored in currentUser.username. If they've upvoted a topic, their username will also be added to the array of upvotes in topic.upvotes.
The issue I'm facing is that topic.upvotes stores an array of values. For example, if Kenneth and Tyler both upvote a topic, topic.upvotes = {"Kenneth":"Kenneth","Tyler":"Tyler"}.
What I need to determine is whether a user has upvoted a topic so that I can apply conditional CSS to visually indicate that they have already voted on that topic.
I've been attempting this with the following code:
ng-class="{user_has_upvoted : signedIn() && topic.upvotes === currentUser.username}"
My goal is to add the user_has_upvoted class to the div only if the user is signed in and has actually upvoted the topic.
However, comparing topic.upvotes (an array) to currentUser.username (a string) using == or === does not work as expected.
I was hoping to use some sort of inArray() function, but I haven't found anything in angular that fits my needs.
Any suggestions or advice would be greatly appreciated. Thank you!