0
I have a.service Profile that broadcasts an event for two components that don’t communicate. By clicking on the Profile Component link, it triggers the "Perfilservice.emitirBeneficios.Emit('profile.benefitsOpcionais')" and redirects to Perfilopcionaiscomponent. However, the content does not appear on the console.log. However, if I go back and do it again, it emits.
//Profiling
constructor(private authService: AuthService, private config: AppConfig, private http: HttpClient, private router: Router ){ }
static emitirBeneficios = new EventEmitter();
//Profile
redirect(perfil: Perfil) {
PerfilService.emitirBeneficios.emit(perfil.beneficiosOpcionais)
this.router.navigate(['/perfil/opcionais']);
//Perfilopcionaiscomponent
ngOnInit() {
PerfilService.emitirBeneficios.subscribe(beneficiosOpcionais =>
console.log(beneficiosOpcionais));
}