• Register
0 votes
3.5k 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()">
6 5 3
7,540 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.

9 7 4
38,600 points

Related questions

0 votes
1 answer 12 views
12 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 2 views
2 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.4k points
0 votes
1 answer 2 views
2 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.4k points
0 votes
1 answer 44 views
44 views
Problem: form submission canceled because the form is not connected
asked Feb 18 charles mathews 5.5k points
0 votes
1 answer 91 views
91 views
Problem: expected validator to return promise or observable.
asked Feb 14 Shovo210 13.3k points
0 votes
1 answer 2 views
2 views
Problem: As I mentioned in my previous query, I'm having difficulties with my learning; I've tried searching the web but haven't been able to find adequate information; could you assist me in continuing my project?
asked Mar 29 tuhin1 48.4k points
0 votes
1 answer 16 views
16 views
Problem: How can I fix this : Can't bind to 'formcontrol' since it isn't a known property of 'input'
asked Mar 14 Wafa Abu Yousef 6.1k points
0 votes
1 answer 2.2K views
2.2K views
Problem : I am beginner in using Angular material. I am trying to use autocomplete component in the Angular2 project. Please find below the code written for my component. import {Component, OnInit} from "@angular/core"; import {ActivatedRoute, Router} from "@angular/router"; ... ; I am struggling with this issue from past 2 days but unable to resolve it. Can somebody help me in fixing this issue?
asked Feb 27, 2020 mphil 2.3k points
0 votes
1 answer 1 view
1 view
Problem: Please help me on set of similar things within a larger group
asked 3 days ago rakib1 51.5k points