Angular2 If ngModel is used within a form tag, either the name attribute must be set or the form Angular2 If ngModel is used within a form tag, either the name attribute must be set or the form angular angular

Angular2 If ngModel is used within a form tag, either the name attribute must be set or the form


If ngForm is used, all the input fields which have [(ngModel)]="" must have an attribute name with a value.

<input [(ngModel)]="firstname" name="something">


As every developer have a common habit, not to read the complete error, just read the first line and start looking for answer from someone else :):) I am also one of them, that's why I am here:

Read the error, clearly saying:

Example 1: <input [(ngModel)]="person.firstName" name="first">Example 2: <input [(ngModel)]="person.firstName" [ngModelOptions]="{standalone: true}">

What more we need to understand this error?

Use any one option everything will work smooth.


In my case the error happened because below in html markup one more line existed without the name attribute.

<form id="form1" name="form1" #form="ngForm">    <div class="form-group">        <input id="input1" name="input1" [(ngModel)]="metaScript" />        ...         <input id="input2" [(ngModel)]="metaScriptMessage"/>    </div></form>

But the browser still reports the first row has the error. And it's difficult to discover the source of mistake if you have other elements between these two.screenshot of chrome devtools showing the error