JHipster * jhiHasAnyAuthority指令检查“否". [英] JHipster *jhiHasAnyAuthority directive check for "no authority"

查看:204
本文介绍了JHipster * jhiHasAnyAuthority指令检查“否".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用户没有权限(未登录)时可以看到一个条件,但是我需要先检查该权限,因此当用户登录时,我将看不到内容

I need to make a condition that is seen when the user has no authority (it is not logged in), but I need to check for that authority first, so when the user is logged in, I will not see the content.

我正在使用JHipster项目中的'jhiHasAnyAuthority'指令.

I'm using the 'jhiHasAnyAuthority' directive from the JHipster project.

<div *jhiHasAnyAuthority="''">This should appear.... when the VISITOR is NOT logged </div>

这在有权限的情况下有效(如果您想知道):

This works when there is an authority (in case you wonder):

<div *jhiHasAnyAuthority="['ROLE_ADMIN', 'ROLE_USER']">This should appear.... when ADMIN or USER is logged </div>
<div *jhiHasAnyAuthority="'ROLE_ADMIN'">This should appear.... when ADMIN is logged </div>

所以我尝试了不同的替代方法,例如:

So I have tried different alternatives like:

<div *jhiHasAnyAuthority="''">This should appear.... when Blank is NOT logged </div>

但是它们不起作用!

注意:我不需要将文本放在普通的DIV中,因此,如果用户未登录,它就会出现,因为登录时也会出现.

NOTE: I do not need to just put the text in a normal DIV so it will appear if the user is not logged, cause when it is logged it will also appear.

谢谢

推荐答案

您正在使用的* jhiHasAnyAuthority指令是JHipseter项目的一部分.

The *jhiHasAnyAuthority directive that you are using is part of the JHipseter project.

它的源代码可以在如果您查看源代码,将会看到它不支持否定测试,并且我假设检查"HasAnyAuthority"中是否为空或null的授权字符串与检查用户是否没有权限.

If you look at the source code, you'll see that it doesn't support a negative test, and I'd assume that checking "HasAnyAuthority" for an authority string that is empty or null is not the same thing as checking that the user has no authority.

因此,您似乎无法使用此指令来测试是否缺少授权, 该指令也似乎不支持* ngIf那样的if/else语法.

So, it appears that you cannot use this directive to test for the absence of an authority, nor does the directive appear to support an if/else syntax like *ngIf does.

我认为做您想要做的唯一方法是编写基于* jhiHasAnyAuthority的自定义指令,或者修改* jhiHasAnyAuthority以添加所需的行为.

I think that the only way to do what you want is to write either write a custom directive based on *jhiHasAnyAuthority, or modify the *jhiHasAnyAuthority to add the desired behavior.

无论哪种情况,如果都能正常工作,最好向JHipster项目提交拉取请求.

In either case, if you get it working, it would be nice to submit a pull request to the JHipster project.

这篇关于JHipster * jhiHasAnyAuthority指令检查“否".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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