• Register
0 votes
5.4k views

Problem :

I am facing following error from the Angular 2

core.umd.js:5995 EXCEPTION: Uncaught (in promise): Error: Error in app/model_exposure_currencies/model_exposure_currencies.component.html:57:18 caused by: If ngModel is used within a form tag, either the name attribute must be set or the form control must be defined as 'standalone' in ngModelOptions.

Example 1: <input [(ngModel)]="person.myfirstName" name="myfirst">
Example 2: <input [(ngModel)]="person.myfirstName" [ngModelOptions]="{standalone: true}">
<td *ngFor="let lag of ce.lags">
    <div class="form-group1">
        <input name="myname" [(ngModel)]="lag.myname" [ngModelOptions]="{standalone: true}"  class="form-control" pattern="[0-9]*(\.[0-9]+)?" required>
    </div>
</td>

Below is my form tag:

<form #f="ngForm" (ngSubmit)="onSubmit()">
7.5k points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

Try following code to fix your issue...

<input type="text" class="form-control" name="myname" placeholder="Name"required minlength="4" #myname="ngModel" ngModel>
<div *ngIf="myname.errors && (myname.dirty || myname.touched)">
<div [hidden]="!myname.errors.required" class="alert alert-danger form-alert">
Please enter your name.
</div>
<div [hidden]="!myname.errors.minlength" class="alert alert-danger form-alert">
Enter name greater than four characters.
</div>
</div>

 

OR

 I simply added the name attribute for the select and checkbox and that fixed my issue. As shown below :

<mat-select placeholder="Select the option" name="Select" [(ngModel)]="sample.stat"> <!--HERE: please Observe the "name" attribute -->
<input id="Input" type="text" placeholder="Enter only number" aria-label="Number" matInput [formControl]="FormControl" required [(ngModel)]="number">  <!--HERE -->
<mat-checkbox name="Check" [(ngModel)]="isRight">Check!</mat-checkbox> <!--HERE: Please Observe the "name" attribute -->

As you can see I added the name attribute. It is not mandetory to be  same as your ngModel name. Just providing the correct name attribute will fix your issue.

38.6k points

Related questions

0 votes
1 answer 47 views
47 views
Problem: any help! I will be thankful: If ngmodel is used within a form tag, either the name attribute must be set or the form.
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
0 answers 24 views
24 views
Problem: As I previously stated in my question, I am having difficulty learning. Could someone help assist me in completing my project?
asked Mar 29 tuhin1 48.9k points
0 votes
1 answer 16 views
16 views
Problem: Is there someone who can assist me in resolving this issue &ldquo;Name the normal form is used to prevent most common update anomalies&rdquo;?
asked Mar 30 tuhin1 48.9k points
0 votes
1 answer 435 views
435 views
Problem: form submission canceled because the form is not connected
asked Feb 18 charles mathews 5.5k points
0 votes
1 answer 8 views
8 views
Problem: What is wrong here : There is no directive with "exportas" set to "ngform" ("?
asked Jun 24 Chi Omega 168k points
0 votes
1 answer 51 views
51 views
Problem: What am I supposed to do here : There is no directive with exportas set to ngform?
asked May 23 Florina Gulnar 106k points
0 votes
1 answer 263 views
263 views
Problem: expected validator to return promise or observable.
asked Feb 14 Sabbir Hossain 14.6k points
0 votes
1 answer 12 views
12 views
Problem: I've tried but haven't had any success with this: Ngmodel cannot be used to register form controls with a parent formgroup directive?
asked Jun 14 akhi 125k points
0 votes
1 answer 14 views
14 views
Problem: Please help me on set of similar things within a larger group
asked Apr 9 rakib1 51.5k points
0 votes
1 answer 22 views
22 views
Problem: I'm looking for a solution : How to get multiple checkbox value in angular 6?
asked May 25 Florina Gulnar 106k points