Javascript function returns Undefined instead of Boolean value

Asked

Viewed 99 times

0

I’m trying to get my function to return true or false, but it always returns me Undefined. I believe my logic is right.

onChangeCategoria(categoria: any, itemchecked) {

    this.itemcheckado = itemchecked;

    if (!categoria.selecionado) {
      this.services.confirmation.confirm({
        message: `A categoria ${categoria.nome} ainda
        não foi configurada para essa solicitação! Deseja configurar?`,
        accept: () => {
          const { id, nome, quantidadeDePessoas } = categoria;
          this.categoriaSelecionada = {
            id,
            nome,
            quantidadeDePessoas,
            paginaAtual: 1
          };
          categoria.selecionado = true;
          this.adicionarCategoria();
          this.itemcheckado.target.checked = true;
    }, reject: () => {
      categoria.selecionado = categoria.selecionado;
      this.itemcheckado.target.checked = false;
    }
  })} else {
    this.itemcheckado.target.checked  = this.confirmarRemocaoCategoria(categoria);
    categoria.selecionado = false;
  }
}

  confirmarRemocaoCategoria(categoria: any) {
    this.services.confirmation.confirm({
      message: `Deseja realmente remover a categoria ${categoria.nome}?`,
      accept: () => {
        if (this.novaSolicitacao()) {
          this.removerCategoriaSelecionada(categoria);
        } else {
          this.removerCategoria(categoria);
        }
        return false;
      },
      reject: () => true
    });
  }
  • What function would be??

  • My onChangeCategory calls Confirm Removal, which should return me true or false. but returns Undefined

  • 1

    I have not seen any Return in this function

  • Yeah, I’m trying so far to figure out if it’s the first or the second that returns Undefined.

1 answer

0


Paul, it turns out that your function returns a Boolean as the consumption of a service, so it stays with an asynchronous behavior, you would have to work with async/await or refactoring the code in some way, for example, sending this.itemcheco.target as a parameter to the function confirm.

  • makes sense, in my case there would be no way to pass as parameter. So I’ll have to work with async/await.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.