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

205
Visualizações
Angular double curly braces expressions being executed multiple times on mouse down and up

In our Angular app, given code like the following:

<div>{{ aGetProperty }}</div>

<div>{{ aMethod() }}</div>

Whenever I click anywhere on the page, these expressions are evaluated multiple times. That is, if I put a console.log('hello') in aMethod, every time I press down on either the left or right mouse button, hello is outputted to console multiple times and again multiple times on mouse up.

Anyone know what could be causing this issue? I have not bound any click, mouse up/down events for the component or anything above it (as far as I can tell). Thanks.

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

0

Angular actually patches the browsers's low-level API: for example the addEventListener is patched to check for changes in DOM and rerender the view. Thus, when you click on the DOM elements Angular will run change detection and your method calls in DOM will get executed. In other words: it's a bad practice to bind methods from DOM - unless it's explicitly an on/click event - because the method will get executed on each change detection in lifecycle. Of course, sometimes you'd indeed want some of your methods to fire on each change, but make sure that's exactly what you want.

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