Property 'login' has no initializer and is not definitely assigned in the constructor.ts(2564)

62 views
Skip to first unread message

pja...@gmail.com

unread,
May 27, 2021, 9:20:51 AM5/27/21
to Angular and AngularJS discussion
I'm getting this error:

Property 'login' has no initializer and is not definitely assigned in the constructor.ts(2564)

How can I solve this?

Below code of my component

import { Component, OnInit } from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {Router} from '@angular/router';
import {UserService} from '../shared/service/user.service';
import {LoginRequest} from '../shared/model/login.request';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {

  public form: FormGroup;
  public login: LoginRequest;
  public error: boolean;

  constructor(private router: Router, private userService: UserService) { }

  ngOnInit(): void {
    this.error = false;
    this.login = new LoginRequest();
    const fb = new FormBuilder();
    this.form = fb.group({
      user: [null, [Validators.required]],
      newPassword: [null, [Validators.required, Validators.minLength(6)]]
    });
  }

  get disableButtonOk(): boolean {
    return this.form.invalid;
  }

  signing(): void {
    this.userService.login(this.login)
      .subscribe(
        () => {
          this.router.navigate(['/reset-password']);
        },
        () => this.error = true // TODO: tratar erro interno de servidor
      );
  }
}
Reply all
Reply to author
Forward
0 new messages