【问题标题】:On button click check which radio button selected in angular 4在按钮上单击检查在角度 4 中选择了哪个单选按钮
【发布时间】:2019-01-13 03:58:11
【问题描述】:

我有两个单选按钮和一个按钮,并在选择我想隐藏的单选按钮时以角度 4 显示 div。这是我的代码 My Code。选择单选按钮后,单击按钮显示隐藏 div。请帮忙。

<div>
<div class="custom-control custom-radio">
  <input type="radio" id="customRadio1" name="customRadio" class="custom-control-input">
  <label class="custom-control-label border rounded px-5 py-2 mt-3 shadow-sm w-100" for="customRadio1">
  <span class="font-weight-bold">Radio Button 1</span>
  </label>
</div>
<div class="custom-control custom-radio">
  <input type="radio" id="customRadio2" name="customRadio" class="custom-control-input">
  <label class="custom-control-label border rounded px-5 py-2 mt-3 shadow-sm w-100" for="customRadio2">
  <span class="font-weight-bold">Radio Button 2</span>
</label>
</div>

<button>Show Content</button>
</div>


<div style="display:none;">
Radio Button 1 Content
</div>
<div style="display:none;">
Radio Button 2 Content
</div>

【问题讨论】:

  • 到目前为止您尝试过什么?你能添加任何尝试吗?
  • 我是 Angular 4 的新手,我已经写了这个

标签: html angular radio-button angular5 angular4-forms


【解决方案1】:

您可以为此使用[(ngModel)]

我在 Stackblitz

上创建了一个演示
<div *ngIf="showcontent=='radio1'">
Radio Button 1 Content
</div>
<div *ngIf="showcontent=='radio2'">
Radio Button 2 Content
</div>

【讨论】:

  • 我不确定这是否真的有效,老实说解释你的思维过程
  • 只是忽略了按钮
  • 谢谢,但这仅适用于单选按钮单击。我想用户选择单选按钮,然后单击“显示内容”按钮,然后将显示内容。你能帮忙吗
猜你喜欢
  • 2011-07-12
  • 2012-04-17
  • 1970-01-01
  • 2022-09-22
  • 2014-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多