angular - primeng 单选按钮如何更改已选中
问题描述
我正在使用 PrimeNg 单选按钮。默认情况下不选中。我希望能够以编程方式使用 javascript 或 typescript 来检查单选按钮。
我尝试了以下但它不起作用。
<p-radioButton inputId="taken" id="taken" name="groupname" value="true" class="col-sm-3 pl-3" [(ngModel)]="modalTaken"></p-radioButton>
document.getElementById("taken").checked=true;
我希望能够更改单选按钮进行检查。因为它在普通单选按钮(不是primeng单选按钮)中工作。
解决方案
HTML:
<p-radioButton inputId="taken" id="taken" name="groupname" value="true" label='true' class="col-sm-3 pl-3" [(ngModel)]="modalTaken"></p-radioButton>
TS:
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
modalTaken = 'true';
}
您modalTaken
必须匹配单选按钮的值。如果您有一个带有值的单选按钮,value='dog'
您modalTaken='dog'
应该看起来像这样。
推荐阅读
- r - 具有因子水平的双色热图
- node.js - 使用 FireStore 云功能进行课程的条带化支付
- javascript - 如何将 React js 项目从 15.6 更新到 16.8?
- javascript - minlength 验证器在猫鼬中不起作用
- algorithm - 最大可能分数
- spring-boot - KafkaConsumer 没有轮询所有消息
- html - safari 没有显示带阴影的圆形 div
- curl - 上传图片时出现错误 {"name":"Bad Request","message":"Unsupported image type","code":0,"status":400}
- css - Bootstrap Carousel 的问题(图像显示但不滑动/更改)
- java - Java中ImageIcon上的内存泄漏