I have a Profile.service that issues an event to two components that do not communicate. By clicking on the ProfileComponent link, it triggers the "ProfileService.emitBeneficies.emit ('profile.benefits')" and redirects to theComponentOptionalProfile. However, the content in the console.log does not appear. However, if I come back and do it again, it will issue.
// ProfileService
constructor(private authService: AuthService, private config: AppConfig, private http: HttpClient, private router: Router ){ }
static emitirBeneficios = new EventEmitter();
// ProfileComponent
redirect(perfil: Perfil) {
PerfilService.emitirBeneficios.emit(perfil.beneficiosOpcionais)
this.router.navigate(['/perfil/opcionais']);
// ProfileOptionalComponent
ngOnInit() {
PerfilService.emitirBeneficios.subscribe(beneficiosOpcionais =>
console.log(beneficiosOpcionais));
}