Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

211
Visualizações
Why does using 'signUp' function appears "Not all code paths return a value"?

I'm not a technically person, just a begginer. Could you please help? I don't really understand what kind of problem do i have. I'm using 'SingUp' function and have such an error discription in my VSC: "(method) RegComponent.signUp(): false | undefined Not all code paths return a value." What I'm doing wrong? I tried to write return: false after the last "else if" block. But something happened and all my code below turned transparent.

There is my reg.component.ts

import { Component, OnInit } from '@angular/core';
import { FlashMessagesService } from 'angular2-flash-messages';
import { UnsubscriptionError } from 'rxjs';
import { AuthService } from '../auth.service';
import { Router } from '@angular/router';


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

  name!: string
  login!: string
  email!: string
  password!: string

  constructor(
    private _flashMessagesService: FlashMessagesService,
    private authService: AuthService,
    private router: Router
  ) { }

  ngOnInit(): void {
  }

  signUp() {
    const user = {
      name: this.name,
      login: this.login,
      email: this.email,
      password: this.password,
    }
    if(!user.name) {
      this._flashMessagesService.show('Enter your name!', 
      { cssClass: 'alert-danger', timeout: 3000 });
      return false
    }
    else if(!user.login) {
      this._flashMessagesService.show('Enter your login!', 
      { cssClass: 'alert-danger', timeout: 3000 });
      return false
    }
    else if(!user.email) {
      this._flashMessagesService.show('Enter your email!', 
      { cssClass: 'alert-danger', timeout: 3000 });
      return false
    }
    else if(!user.password) {
      this._flashMessagesService.show('Enter your password!', 
      { cssClass: 'alert-danger', timeout: 3000 });
      return false
    }
    


    this.authService.registerUser(user).subscribe( data => {
      if (!data.success) {
        this._flashMessagesService.show(data.msg, 
        { cssClass: 'alert-danger', timeout: 3000 });
        this.router.navigate(['/reg'])
      } else {
        this._flashMessagesService.show(data.msg, 
          { cssClass: 'alert-success', timeout: 3000 });
          this.router.navigate(['/auth'])
      }
    })

  }

}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda