Good.
I am making a registration form in ionic and when using the ngModel property it gives me the following error
Uncaught (in promise): 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}">
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.TemplateDrivenErrors.missingNameException (http://localhost:8100/build/vendor.js:26062:15)
at NgModel._checkName (http://localhost:8100/build/vendor.js:26380:34)
at NgModel._checkForErrors (http://localhost:8100/build/vendor.js:26359:14)
at NgModel.ngOnChanges (http://localhost:8100/build/vendor.js:26264:14)
at checkAndUpdateDirectiveInline (http://localhost:8100/build/vendor.js:11210:19)
at checkAndUpdateNodeInline (http://localhost:8100/build/vendor.js:12714:17)
at checkAndUpdateNode (http://localhost:8100/build/vendor.js:12653:16)
at debugCheckAndUpdateNode (http://localhost:8100/build/vendor.js:13517:59)
at debugCheckDirectivesFn (http://localhost:8100/build/vendor.js:13458:13)
at Object.eval [as updateDirectives] (ng:///AppModule/RegistroPage.ngfactory.js:234:5)
And my code is the following to not make it so long I put an input
log.html
<ion-input type="text" [(ngModel)]="nombreApellidos" ></ion-input>
log.ts
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
@IonicPage()
@Component({
selector: 'page-registro',
templateUrl: 'registro.html',
})
export class RegistroPage {
nombreApellidos: string;
constructor(public navCtrl: NavController, public navParams: NavParams) {
}
}
if I remove [(ngModel)]="firstNameLastName" from the ion-input everything is displayed perfectly. Thank you in advance.
And I found the solution the problem is that when you use in the ion-input [(ngModel)] they must also have the name="" property
It would look like this: