0

I have an input field where a user should be able to change his name. So can manipulate the field, and when terminated the new string should be stored as a new username? I tried to achieve that with formbut I get this error: Error: Template parse errors: Can't bind to 'formGroup' since it isn't a known property of 'form'.

Here is my code

page.html

<form [formGroup]="form" (ngSubmit)="changeName()">
    <ion-list no-border>

        <ion-list-header>
          My Account
        </ion-list-header>

        <ion-item >
           
       <ion-input>{{username}}</ion-input>
        </ion-item>
  ...

      </ion-list>
    </form>

page.ts

import { FormGroup, FormControl, Validators} from '@angular/forms';
...
form: FormGroup;

public usernameInput = '';
...

constructor() {}

...

changeName() {
  this.usernameInput = '';
}

 ngOnInit() {
    this.form = new FormGroup({
     username: new FormControl(null, {
       updateOn: 'submit',
       validators: [Validators.required, Validators.maxLength(20), Validators.minLength(1)]
     })
 });
}
Colin Ragnarök
  • 1,062
  • 9
  • 18

1 Answers1

2

Import the ReactiveFormsModule to your feature module.

iams0nus
  • 481
  • 3
  • 8