tag-input doesn't render inside ReactiveForm
See original GitHub issueI’m using Ionic 2 (but don’t think that should matter). If I put this markup in my template outside of a form
element it renders and works correctly:
<tag-input [ngModel]="['aa', 'bb']" [editable]="true" placeholder="test placeholder"></tag-input>
If I put the same code inside a form:
<form novalidate [formGroup]="form">
<tag-input [ngModel]="['aa', 'bb']" [editable]="true" placeholder="test placeholder"></tag-input>
I get this error when that page renders:
EXCEPTION:
ngModel cannot be used to register form controls with a parent formGroup directive. Try using
formGroup's partner directive "formControlName" instead. Example:
<div [formGroup]="myGroup">
<input formControlName="firstName">
</div>
In your class:
this.myGroup = new FormGroup({
firstName: new FormControl()
});
Or, if you'd like to avoid registering this form control, indicate that it's standalone in ngModelOptions:
Example:
<div [formGroup]="myGroup">
<input formControlName="firstName">
<input [(ngModel)]="showMoreControls" [ngModelOptions]="{standalone: true}">
</div>
When I add [ngModelOptions]="{standalone: true}"
the input doesn’t render (but no errors).
I also tried it with an attribute defined in the FormGroup
and using formControlName="myattributenamehere"
and it doesn’t render (and no errors).
Do you see what I’m doing wrong or is there an example of using this input element within a reactive form using FormBuilder
?
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
how to make dynamic input inside form tag with reactive form
i've faced another problem and the inner formgroup is seperated than the outer group. when change the data in the inner form it's...
Read more >Introduction to forms in Angular
In reactive forms each form element in the view is directly linked to the form model (a FormControl instance). Updates from the view...
Read more >FormGroup and FormControl in Angular - LogRocket Blog
In Angular, form controls are classes that can hold both the data values and the validation information of any form element. Every form...
Read more >Working with Angular 4 Forms: Nesting and Input Validation
Forms in Angular applications can aggregate the state of all inputs that are under that form and provide an overall state like the...
Read more >Rendering Your Angular Reactive Form Control Value in a ...
<form [formGroup]="form"> <input placeholder="Email" type="email" formControlName="email"> </form> · <p>{{email}}</p> · get email() { return this.form.get('email') ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
In case anyone else has this same issue add the
item-content
attribute to thetag-input
:For my layout I also added
class="tag-input"
to the wrappingion-item
so I could fix the horizontal alignment of thetag-item
via this addition toapp.scss
:@saschwarz happy to help 😃