默认情况下,Angular 2选中单选按钮 [英] Angular 2 check radio button by default

查看:82
本文介绍了默认情况下,Angular 2选中单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试默认检查我的单选按钮为零值.我正在尝试使用[checked]='true'属性.但这是行不通的.

I am trying to check my radio button with zero value by default. I am trying to use the [checked]='true' attribute. But that does not work.

<input type="radio" name="unitTrusts-pnl" id="unitTrusts-pnl0" class="with-gap" [value]="0" [(ngModel)]="unitTrustsPnl"  [checked]='true'>
<input type="radio" name="unitTrusts-pnl" id="unitTrusts-pnl0" class="with-gap" [value]="1" [(ngModel)]="unitTrustsPnl">

演示

https://stackblitz.com/edit/angular-jj9gib

推荐答案

由于按钮已绑定到变量,请尝试设置该变量:

Since the buttons are bound to a variable, try setting the variable instead :

unitTrustsPnl = 0;

这篇关于默认情况下,Angular 2选中单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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