Angular 18 FormBuilder error Property not initialized

Discussão em 'Angular' iniciado por Diego, Novembro 10, 2024.

  1. Diego

    Diego Guest

    I am doing a Dummy in Angular 18, I am using Reactive Forms and I an trying to implement FormBuilder

    I have this constructor in my .ts

    constructor(private builder:FormBuilder){

    }


    Then I try to create the form with the validations.

    registerform= this.builder.group({
    username:this.builder.control('',Validators.required),
    name:this.builder.control('',Validators.compose([Validators.minLength(5),Validators.required])),
    email:this.builder.control('', Validators.compose([Validators.email,Validators.required])),

    });


    But I got an error... saying

    Property 'builder' is used before initialization


    The html has his header.

    <form class="example-form" [formGroup]="registerform" (ngSubmit)="ProceedRegister()">


    I saw others examples that do not throw any errors.

    How can I initialized this property?

    Thanks

    Continue reading...

Compartilhe esta Página