“隐藏”用括号没有角度的工作
我将[hidden] =“ true”
添加到Angular中的HTML元素,但该元素仍然可见。我注意到,当我从附近删除
[]
时,该元素现在根据需要隐藏。为什么[hidden] =“ true”
与括号合作?我在stackoverflow和其他地方看到了许多引用,但无法使其起作用。这是弃用吗?
I add [hidden]="true"
to an HTML element in Angular, but the element is still visible. I noticed that when I remove the []
from around hidden
, the element is now hidden as desired. Why won't [hidden]="true"
work with brackets? I see many references to it on stackoverflow and elsewhere but can't get it to work. Is this deprecated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试一下。希望它对您有帮助。
try this. hope it will help you.
它应该像您的解释一样工作。否则,其他东西将覆盖隐藏。例如:
某些样式可以覆盖
隐藏
。样式和课程可以从某个地方继承?可以明确不允许这样做。如果您不想更改冲突的班级而只是强迫这一点,这可能会很有用。
替代方法可能是使用
dispaly:无
:此输入是隐藏的,但仍在DOM中。
It should work like you explained. Otherwise something else is overwriting hidden. For example:
Some styles can overwrite
hidden
. Styles and classes may be inherited from somewhere?It would be possible to explicitly not allow that. This might be useful if you don't want to change conflicting classes rather just force this on.
Alternative could be to use
dispaly: none
:This input is hidden but still in the DOM.
感谢大家的回答。我只是意识到这是因为我试图在
index.html
的内部使用它,该在角度入口点之外。Thanks to everyone for your responses. I just realized this is because I'm trying to use this inside of
index.html
, which is outside of the Angular entry point.您可以在HTML文件中使用样式的“可见性”。
可见性要么是“可见”或“隐藏”
,在您的.TS文件中:可见性:
You can use the style "visibility" inside your html file.
visibility is either "visible" or "hidden"
With, in your .TS file: