在angular2中选中复选框时如何动态生成textarea
How to generate textarea dynamically when checkbox is checked in angular2
我是Angular2的新手,想在angular2中选中checkbox时动态生成textarea,取消选中checkbox时删除textarea,有没有更好的解决方案?提前致谢。
<input type="checkbox" #mycheckbox />
<textarea *ngIf="mycheckbox.value"></textarea>
设置ngModel
然后存储为变量:
<input type="checkbox" #isVisible="ngModel" [(ngModel)]="isTextareaVisible">
然后使用 *ngIf
切换它:
<textarea *ngIf="isVisible"></textarea>
旁注:如果这是在表单标签内,请不要忘记将 name="isTextareaVisible"
属性添加到 input
,否则 angular 会报错。
我是Angular2的新手,想在angular2中选中checkbox时动态生成textarea,取消选中checkbox时删除textarea,有没有更好的解决方案?提前致谢。
<input type="checkbox" #mycheckbox />
<textarea *ngIf="mycheckbox.value"></textarea>
设置ngModel
然后存储为变量:
<input type="checkbox" #isVisible="ngModel" [(ngModel)]="isTextareaVisible">
然后使用 *ngIf
切换它:
<textarea *ngIf="isVisible"></textarea>
旁注:如果这是在表单标签内,请不要忘记将 name="isTextareaVisible"
属性添加到 input
,否则 angular 会报错。