【问题标题】:Want to add Placeholder to Dynamically Generated Field Angular Material想要将占位符添加到动态生成的字段角度材质
【发布时间】:2020-09-12 23:16:27
【问题描述】:

我有一个 Angular Reactive 表单,其中输入字段是动态生成的 我想更改动态生成的输入字段的占位符 基于用户在第一个文本框中选择的内容。

所以假设用户在第一个文本框中输入了任何内容,因此我想更改第二个文本框的值等等..

请注意所有输入字段都是动态生成的,所以我不能像这样更新占位符: somePlaceholder : string = "新值";

<form [formGroup]="productForm">
            <div formArrayName="products">
                <div *ngFor="let prd of products().controls; let i=index" [formGroupName]="i">
                    <div class=""> 

                        <mat-form-field  class="">
                            <input OnlyNumber="true" DecimalPlaces="3" (keyup)="ChangePlaceHolderValue(i)"  [errorStateMatcher]="matcher" maxlength="16"  matInput id="txtProdFees" name="txtProdFees" formControlName="txtProdFees" class="form-control">
                            <mat-error *ngIf="this.productFrmArray.controls[i].controls.txtProdFees.errors?.greaterthanzero">Value should be greater than {{minProdFees}}</mat-error>
                            <mat-error *ngIf="this.productFrmArray.controls[i].controls.txtProdFees.errors?.maxError">Fees cannot be greater than {{maxProdFee}}</mat-error>
                            <mat-error *ngIf="this.productFrmArray.controls[i].controls.txtProdFees.errors?.invalid">Fees should be greater than {{productFrmArray.controls[i].controls.txtProdFees.errors?.lowerfee}}</mat-error>
                        </mat-form-field> 
                    </div> 
                </div>
            </div>
            </form>

【问题讨论】:

  • 如果能提供 stackblitz 就好了。到目前为止,我只能说“你可以做到!” (:
  • 请向我们展示您的模板和表单组的创建。
  • 我已经添加了 HTML 代码,所以根据用户在第一个文本框中键入的内容,我想更改下一个文本框中的占位符值等等,所以占位符变量不能只是一个。跨度>

标签: angular angular-material


【解决方案1】:

只使用一个变量

<input matInput [placeholder]="variable">
//in ts
variable="Ex. pizza"

注意:&lt;mat-placeholder&gt; 已弃用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-14
    • 2019-03-25
    • 1970-01-01
    • 2018-05-15
    • 2020-09-06
    • 2015-04-20
    相关资源
    最近更新 更多