我的模板中有两个radio buttons
。选择按钮时,input
应为每个按钮显示不同的文本字段button
,而其他字段应隐藏。
我怎样才能做到这一点Angular
?
我尝试使用*ngIf
and ngModel
,但无法解决此问题。
我的模板中有两个radio buttons
。选择按钮时,input
应为每个按钮显示不同的文本字段button
,而其他字段应隐藏。
我怎样才能做到这一点Angular
?
我尝试使用*ngIf
and ngModel
,但无法解决此问题。
看一看:
HTML
Type 1: <input type="radio" name="foo" value="type_1" [(ngModel)]="radioBtn">
<br>
Type 2: <input type="radio" name="foo"
[(ngModel)]="radioBtn" value="type_2">
<br>
<ng-container *ngIf="radioBtn == 'type_1'">
Type 1: <input type="text" placeholder="Type 1">
</ng-container>
<ng-container *ngIf="radioBtn == 'type_2'">
Type 2: <input type="text" placeholder="Type 2">
</ng-container>
TS
export class AppComponent {
radioBtn: string = 'type_1';
}
解释:
要使单选按钮起作用,您需要做两件事:
name="foo"
value="bar"