0

I am using Angular 9.

Question

How do I populate the following:

[ngClass]="{'is-invalid': approvalEditFormGroup.get('userName[0][0]').touched && approvalEditFormGroup.get('userName[0][0]').invalid}"

As you can see, I have hard-coded 'userName[0][0]'. Is it possible to replace the 0 values with the i and j variables?

I have the following:

html

<input formControlName="{{getFieldName(i,j)}}" matInput [matAutocomplete]="auto" [ngClass]="{'is-invalid': approvalEditFormGroup.get('userName[0][0]').touched && approvalEditFormGroup.get('userName[0][0]').invalid}">

ts

  public getFieldName(i: number, j: number): string {
    return 'userName['+i+']['+j+']';
  }

1 Answer 1

1

Now the i and j are just part of the string, so you need to use the actual i and j values

<input formControlName="{{getFieldName(i,j)}}" matInput [matAutocomplete]="auto" [ngClass]="{'is-invalid': approvalEditFormGroup.get('userName['+i+']['+j+']').touched && approvalEditFormGroup.get('userName['+i+']['+j+']').invalid}">

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.