Angular 根据是/否单选按钮选择添加和删除角度形式的输入
我正在尝试根据是/否单选按钮选择从角度窗体添加/删除输入 目前,我已经使用ngIf指令实现了这一点,但当我看到时,该属性仍保留在表单的JSON对象中,表单继续保持无效 请提供任何建议,明确删除输入时,没有选择的选项,或建议我一个更好的方法来做到这一点 GitHub回购:Angular 根据是/否单选按钮选择添加和删除角度形式的输入,angular,angular-reactive-forms,formbuilder,Angular,Angular Reactive Forms,Formbuilder,我正在尝试根据是/否单选按钮选择从角度窗体添加/删除输入 目前,我已经使用ngIf指令实现了这一点,但当我看到时,该属性仍保留在表单的JSON对象中,表单继续保持无效 请提供任何建议,明确删除输入时,没有选择的选项,或建议我一个更好的方法来做到这一点 GitHub回购: 提前谢谢 您可以根据单选值更改在表单中添加和删除控件 //Add: this.formTest.addControl('phoneNumber',['', Validators.required]); //Remove: th
提前谢谢 您可以根据单选值更改在表单中添加和删除控件
//Add:
this.formTest.addControl('phoneNumber',['', Validators.required]);
//Remove:
this.formTest.removeControl('phoneNumber');
角度组:
更新:
this.formTest.addControl('phoneNumber',new FormControl('',[Validators.required]));
下面的代码很容易理解:->
<input name="options" [(ngModel)]="options" type="radio" [value]="true" [checked]="options"/> Yes
<input name="options"[(ngModel)]="options" type="radio" [value]="false" [checked]="!options"/> No
<div *ngIf="options">
<input name="displaying input if its true">
</div>
<div *ngIf="!options">
<input name="displaying input if its false"> // In your case don't display input.
</div>
是
不
//在您的情况下,不要显示输入。
Hi,我尝试此操作时出错:this.formTest.addControl('phoneNumber',['',Validators.required]);