Angular 2打字稿:如何根据单选按钮显示下拉列表和文本框 [英] Angular 2 typescript:How to show dropdown and textbox based on radio button

查看:73
本文介绍了Angular 2打字稿:如何根据单选按钮显示下拉列表和文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的UI包含两个单选按钮是"和否",以及如何基于这些单选按钮值显示下拉菜单和文本框.例如,如果用户单击是"收音机,则需要显示下拉菜单;如果用户选中否"收音机,则文本框应使用角度2的打字稿显示.请提供任何链接或帮助我.

解决方案

对饮酒者的答案进行小改动,因为不幸的是,它无法正常工作.单选按钮的值不是 boolean ,而是 string ,因此必须对照字符串值检查这些值,这里我使用"yes"和"no"./p>

所以:

 <输入类型="radio" [(ngModel)] ="radioValue" value =是"/>是< input type ="radio" [(ngModel)] ="radioValue" value ="no"/> NO<选择* ngIf ="radioValue =='是'">< option>某些选项</option></select>< input type ="text" * ngIf ="radioValue =='no'"/> 

这应该让您入门!:)

My UI contain two radio buttons YES and NO, how to show dropdown and textbox based on these radio button values. Example if user click YES radio then need to show dropdown,if user checked NO radio then textbox should show using angular 2 typescript.please anybody provide link or help me to do.

解决方案

Small changes to aholtry's answer as that will not unfortunately work. The values of the radio buttons are not boolean, but string, so the values have to be checked against string values, here I used "yes" and "no".

So:

<input type="radio" [(ngModel)]="radioValue" value="yes" />YES
<input type="radio" [(ngModel)]="radioValue" value="no"/>NO

<select *ngIf="radioValue == 'yes'">
    <option>Some Option</option>
</select>

<input type="text" *ngIf="radioValue == 'no'" />

This should get you started! :)

这篇关于Angular 2打字稿:如何根据单选按钮显示下拉列表和文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆