There's something I've been stuck on for a couple days now. I would like to display an item based on the current user (id).
For an example:
<!-- if current user has already 'liked' this post -->
Show 'UnLike' button
<!-- else -->
Show 'Like' button
<!-- end -->
How do you use conditional statements based on the current user's id in Angularjs?
I'm using Rails as my backend along with Devise, if it helps..
Lets make it easy.
First, setup gon.
At your Rails controller level, wherever needed, or in before_filter (before_action in Rails 4), do:
gon.current_user = { id: current_user.id }
then on Angular side:
app.service 'sessionService', [ '$window', ($window)->
factory =
current_user: ->
$window.gon.current_user
factory
]
Then inject you session service and you'll have access to the current_user object via the method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With