“隐藏”用括号没有角度的工作

发布于 2025-02-10 00:36:39 字数 209 浏览 2 评论 0原文

我将[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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

从此见与不见 2025-02-17 00:36:39

尝试一下。希望它对您有帮助。

<div [hidden]="'true'"><div/>

try this. hope it will help you.

<div [hidden]="'true'"><div/>

纵性 2025-02-17 00:36:39

它应该像您的解释一样工作。否则,其他东西将覆盖隐藏。例如:

某些样式可以覆盖隐藏。样式和课程可以从某个地方继承?

<input [hidden]="true" style="display: block">

可以明确不允许这样做。如果您不想更改冲突的班级而只是强迫这一点,这可能会很有用。

[hidden] {
  display: none !important;
}

替代方法可能是使用dispaly:无

<input [style.display]="'none'">

此输入是隐藏的,但仍在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?

<input [hidden]="true" style="display: block">

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.

[hidden] {
  display: none !important;
}

Alternative could be to use dispaly: none:

<input [style.display]="'none'">

This input is hidden but still in the DOM.

浪推晚风 2025-02-17 00:36:39

感谢大家的回答。我只是意识到这是因为我试图在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.

岁吢 2025-02-17 00:36:39

您可以在HTML文件中使用样式的“可见性”。
可见性要么是“可见”或“隐藏”

<div [style.visibility]="'visible'"></div>

<div [style.visibility]="'hidden'"></div>

<div [style.visibility]="showMyDiv ? 'visible' : 'hidden'"></div>

,在您的.TS文件中:可见性:

showMyDiv() {
// return true or false
}

You can use the style "visibility" inside your html file.
visibility is either "visible" or "hidden"

<div [style.visibility]="'visible'"></div>

<div [style.visibility]="'hidden'"></div>

<div [style.visibility]="showMyDiv ? 'visible' : 'hidden'"></div>

With, in your .TS file:

showMyDiv() {
// return true or false
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文