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

雨燕双飞 提交于 2021-02-07 13:34:14

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/11150106/how-can-i-show-or-hide-some-buttons-depend-on-the-users-rights-in-angularjs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!