在angularjs中,如何根据用户的权限显示或隐藏某些按钮? [英] How can I show or hide some buttons depend on the user's rights, in angularjs?

查看:74
本文介绍了在angularjs中,如何根据用户的权限显示或隐藏某些按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于angularjs,我们通常使用纯HTML编写视图.现在我有一个问题:如何显示或隐藏某些按钮取决于用户的权限?

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.

但是由于视图是纯HTML,我该如何控制它?

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

我可以发布请求以将一些数据(例如当前用户ID,商品ID)传递到服务器以进行检查,但是如果有很多按钮,则需要多次请求,这是无效的.

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.

还有更好的方法吗?

推荐答案

您可以使用 ngShow指令.我整理了一些演示,但重要的一点是:

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>

这篇关于在angularjs中,如何根据用户的权限显示或隐藏某些按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆