1

I am making forms through form builder in angularjs2, I want to add formControlName property/attribute of form element like this:

   <input type="text" formControlName={{'client_name' + i}} placeholder="Required" />

How can I do this?

Edit:

I also want to put the validity message beside input element like this: How do I make the client_name inside the ngIf condition block dynamic as well?

<div *ngIf=“! userform.controls['client_name'].valid”>
  Client Name is Not Valid
</div>

It should have same value as {{'client_name' + i}}

4
  • 1
    All that's missing are "" around {{'client_name' + i}} It also might try to actually do addition, but that's an easy fix. Commented Dec 6, 2016 at 17:22
  • Neat! Thanx :D been stuck for a while thanx a ton. Commented Dec 6, 2016 at 17:24
  • Hi Please see my edit as well, would be grateful if u can help? :) Commented Dec 6, 2016 at 17:38
  • Where did you get stuck? did you add the fields to the formgroup? Commented May 2, 2017 at 6:54

1 Answer 1

2

Please use[formControlName]='client_name + i' instead of formControlName={{'client_name' + i}}

And use userform.controls[client_name + i].valid instead of userform.controls['client_name'].valid

For More Information: https://angular.io/guide/dynamic-form

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.