Ng2-select: If ngModel is used within a form tag, either the name attribute must be set or the form

Created on 2 Dec 2017  路  2Comments  路  Source: valor-software/ng2-select

got this on my html

<ng-select  name = "topicUI" 
                            [(ngModel)]="topicsChosen"   
                            [multiple]="true"
                            [items]="items"
                            [disabled]="disabled"
                            (data)="refreshValue($event)"
                            (selected)="selected($event)"
                            (removed)="removed($event)"
                            placeholder="No city selected"></ng-select>

but yet, I'm still getting this error:

ManageLearningPlanComponent.html:458 ERROR Error: 
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.firstName" name="first">
      Example 2: <input [(ngModel)]="person.firstName" [ngModelOptions]="{standalone: true}">
    at Function.webpackJsonp.../../../forms/@angular/forms.es5.js.TemplateDrivenErrors.missingNameException (forms.es5.js:4040)

What am I doing wrong here?
( The only thing I did not do in the instructions is to include ng2-select.css )

Most helpful comment

Had the same issue, I put the name attribute to ng-select like this:

<ng-select name="anyName" ... ></ng-select>

All 2 comments

I've figured what was wrong. I was missing the name attribute of the button too. name="myNameIsTrinity" did the trick.

Why don't you update your demo to throw in the names to avoid this?

Had the same issue, I put the name attribute to ng-select like this:

<ng-select name="anyName" ... ></ng-select>

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cherrydev picture cherrydev  路  5Comments

rkralston picture rkralston  路  3Comments

thanhngvpt picture thanhngvpt  路  5Comments

Kiwi15 picture Kiwi15  路  4Comments

uzumakinaruto123 picture uzumakinaruto123  路  5Comments