【问题标题】:When i click on checkbox, I want to show textbox?当我点击复选框时,我想显示文本框?
【发布时间】:2021-09-13 13:15:45
【问题描述】:

当我点击复选框时,我想显示我的后端参数以拆分为两个文本框。我面临困难,有人可以在这里帮忙吗?这是来自后端。像标签一样的值

模板参数:“命名空间,资源”

我需要在单击复选框上将上述参数拆分为两个文本框。喜欢 命名空间作为标签和文本框,资源作为标签和文本框

请帮忙,谢谢。 html:

<div class="form-check" *ngFor="let product of DisplayProductList">
                                    <label class="form-check-label text-break">
                                  <input class="form-check-input" type="checkbox" formControlName="templateparameter" [value]="true"
                                  [(ngModel)]="product.isChecked" (change)="changeSelection($event)"> {{ product.template_name }}
                                  <span class="form-check-sign">
                                    <span class="check"></span>
                                  </span>
                                </label>
                                </div>

ts:

 changeSelection(event: any) {
    if (event.target.checked) {
      this.selectedItemsList = this.DisplayProductList.filter((product, index) => {
       
        if (product.isChecked == true) {
          return product.isChecked

        }
       
      }
      );
    } 

【问题讨论】:

  • 能否在您的问题中添加一些代码,到目前为止您尝试了什么?
  • 我已经在那里添加了我的代码,当我选中我的复选框时,值即将到来,但我需要将该值拆分为文本框。像标签一样的值。

标签: angular checkbox


【解决方案1】:

下面的行将为您提供 label1 和 label2 作为参数。

let  [ label1, label2 ] =  template_parameter.split(',');

您可以在选择复选框时根据需要动态添加和删除控件

this.yourForm.addControl(label1, new FormControl('', Validators.required));
this.yourForm.removeControl(label1);

在 HTML 中,您可以简单地检查这些表单是否存在,以便在需要时显示它们。

 *ngIf="yourForm.contains(controlName: string)"  

【讨论】:

  • 感谢@Vaira 的回复,我已经以另一种方式做到了。它奏效了。
猜你喜欢
  • 2021-01-25
  • 1970-01-01
  • 2018-08-19
  • 2015-09-14
  • 2020-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-08
相关资源
最近更新 更多