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

180
Visualizações
Angular passing event data doesn't log correctly

So I have the component favorite for the "add to favorites" functionality.

I have the next code in favorite.component.ts (only lines for emitting event)

 import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';

 @Input() isFavorite = false;

 this.change.emit({ newValue: this.isFavorite });

I have the next code in app.component.html:

<favorite [isFavorite]="post.isFavorite" (change)="favButtonChanged($event)"></favorite>

And the next one in app.component.ts:

favButtonChanged(eventArgs: { newValue: boolean }) {
    console.log("Favorite changed", + eventArgs);
  }

The idea is that everytime the button changes (toggles color and html), this event to log in the console "Favorite changed" + 0/1 (a boolean value). It logs: Favorite changed NaN.

Where is the problem?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You wrote console.log("Favorite changed", + eventArgs);

There's a comma , so you're passing two parameters to console.log and the second parameter is + eventArgs which tries to convert eventArgs into a number.

As you declared, eventArgs is clearly not a number (NaN means Not a Number) so the conversion (from the + sign) fails.

You might want to remove that +.

about 4 years ago · Juan Pablo Isaza Relatório

0

here eventArgs is an object which will get NaN due to + you need write eventArgs.newValue which is boolean value & get converted into 1/0 Please try the below code

console.log("Favorite changed ", +eventArgs.newValue)

about 4 years ago · Juan Pablo Isaza Relatório
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