How can I show or hide some buttons depending on user rights in angularjs?

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

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

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

I can send a request to transfer some data (for example, the current user ID, article ID) to the server for verification, but if there are many buttons, I need to request many times, which is inefficient.

Is there a better way to do this?

+6
source share
1 answer

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

<button ng-show="user.id==post.postedby">Delete</button> 
+9
source

Source: https://habr.com/ru/post/918720/


All Articles