我尝试将 ng-switch 与 2 个按钮一起使用,以便根据单击的按钮显示 HTML 元素。我还没有见过这样的例子
到目前为止,这是我的代码:
<button name="withdraw" ng-click="type(name)">Withdraw</button>
<button name="enter" ng-click="type(name)">Enter Amount to Withdraw</button>
<hr>
<div ng-switch="type(name)">
<div ng-switch-when="withdraw">
//code
</div>
<div ng-switch-when="enter">
//code
</div>
</div>
最佳答案
如果您使用相关按钮,请使用单选按钮。
<input type="radio" ng-model="myVar" value="withdraw">withdraw
<input type="radio" ng-model="myVar" value="enter"> enter
在条件中使用模型值
<div ng-switch="myVar">
<div ng-switch-when="withdraw">
<h1>withdraw</h1>
</div>
<div ng-switch-when="enter">
<h1>enter</h1>
</div>
</div>
关于html - 使用带有按钮的 ng-switch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45750920/