Redirect problem at Angular

Asked

Viewed 25 times

1

I’m having a problem rerouting the Angular

Below is the registration-client.componentts file.:

import { Component, OnInit } from '@angular/core';
import { debounceTime } from 'rxjs/operators';
import { FormBuilder } from '@angular/forms';
import { Router } from '@angular/router';


@Component({
  selector: 'app-cadastro-clientes',
  templateUrl: './cadastro-clientes.component.html',
  styleUrls: ['./cadastro-clientes.component.css']
})
export class CadastroClientesComponent implements OnInit {
  formCadastro;
  valoresForm: Object;
  conversao;
  constructor(
    private fb: FormBuilder,
    private router: Router
    ) { }

  ngOnInit() {
    this.formCadastro = this.fb.group({
      data: [''],
      horario: [],
      alfanumerico: [],
      numero: [],
      texto: []
    });
    console.log(this.valoresForm);
    this.formCadastro.valueChanges.pipe(
      debounceTime(1000))
      .subscribe(res => {
        console.log(res);
        this.valoresForm = res;
      });
  }
  
  objetoCadastro() {
    console.log(this.formCadastro.controls);
    this.conversao = JSON.stringify(this.valoresForm);
    localStorage.setItem('objetoCadastro', this.conversao);
    this.router.navigate(['/cadastro-clientes']);

  }
  verificaCadastro() {
    setTimeout(() => {
      if (localStorage.getItem('cadastro')) {
        // TODO REDIRECIIONAR PARA PAGINA DE CADASTRO CONCLUIDO
        this.router.navigate(['']);
      } else {
        return false;
      }
    }, 200);
}
}

I want that after sending the form data, it return to the home page, or any other. None is working.

And by the way, the data is being sent: inserir a descrição da imagem aqui

If anyone can help me...

  • Hi Weslley, try using the routerlink, I think it should work. https://angular.io/api/router/RouterLink

No answers

Browser other questions tagged

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