Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I show or hide some buttons depend on the user's rights, in angularjs?

Tags:

angularjs

With angularjs, we usually use plain HTML to write views. Now I have a question: how can I show or hide some buttons depend on the user's rights?

For example, current page is displaying an article. If the current user is the author or the article, or administrator, then "Delete" button will be displayed.

But since the view is plain HTML, how can I control it?

I can post an request to pass some data(e.g. current user id, article id) to server to check, but if there are many buttons, I need to request many times, which is not effective.

Is there any better way to do this?

like image 337
Freewind Avatar asked Jun 22 '12 04:06

Freewind


1 Answers

You can use the ngShow directive. I put together a little demo, but the important bit is simply:

<button ng-show="user.id==post.postedby">Delete</button>
like image 168
Supr Avatar answered Sep 21 '22 10:09

Supr