Error with ngModel in ionic

0

Good morning.

I'm doing an ionic registration form and using the ngModel propriety 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

registro.html

<ion-input type="text" [(ngModel)]="nombreApellidos" ></ion-input>

registro.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)]="nombreName" of the ion-input everything is shown to perfection Thank you very much in advance.

    
asked by Deivis González González 17.10.2017 в 18:54
source

1 answer

0

And I found the solution the problem is that when using ion-input [(ngModel)] they must also have the property name=""

It would stay like this:

<ion-input type="text" [(ngModel)]="nombreApellidos" name="nombre" ></ion-input>
    
answered by 17.10.2017 / 19:13
source