gpt4 book ai didi

javascript - 是否可以将 ng-switch-when 属性放在多个元素上?

转载 作者:行者123 更新时间:2023-11-30 05:42:49 24 4
gpt4 key购买 nike

我正在尝试使用 ng-switch 切换元素当我设置某个索引时显示特定元素。

ng-switch 正常工作,只是它只显示最后一个 switch 语句。

我在使用这段代码时只显示“第 2 帧”div:

<div ng-switch="frame">
<div ng-switch-when="1">Frame 1</div>
<span>Some permanent text</span>
<span ng-switch-when="2">Text relevant to frame 2</span>
<div ng-switch-when="2">Frame 2</div>
</div>

frame 设置为 2 时,我希望上面显示所有 switch-when

注意:标记不能更改。

  • 我该怎么做?
  • 如果我不能,是否有更好/不同的选择?

最佳答案

嵌套你的标记:

<div ng-switch="frame">
<div ng-switch-when="1">Frame 1</div>
<span>Some permanent text</span>
<div ng-switch-when="2">
<span>Text relevant to frame 2</span>
<div>Frame 2</div>
</div>
</div>

编辑:OP 编辑​​了他的问题以指定标记不能更改。

您不能将相同的 ng-switch-when 应用于多个元素。不过,您可以使用ng-show:

<div>
<div ng-show="frame == 1">Frame 1</div>
<span>Some permanent text</span>
<span ng-show="frame == 2">Text relevant to frame 2</span>
<div ng-show="frame == 2">Frame 2</div>
</div>

DEMO

关于javascript - 是否可以将 ng-switch-when 属性放在多个元素上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19791523/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com