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

160
Visualizações
Why Angular Change Detection re-renderes component if data didn't change?

Basically for what I understand, Angular Change Detection will re render component if a change happened, or to be precise a property used in the template has changed. In any other case it will not (unnecessary) re render that component if the value stayed the same.

Here's the example that I've made, button inside the component triggers CD. Call of that button click event is empty so it doesn't update any value inside the component. Only this used in the template is a getter function that always returns the same simple value.

So if CD compared previous and current value there is no change so why would is seem that component re rendered since the console log inside the getter function was called.

Or it has crossed my mind, the console.log inside the getter was called during CD value comparison and the component did not really re-render.

Here's the example https://angular-playground.stackblitz.io.

import { ChangeDetectionStrategy } from '@angular/core/src/change_detection/constants';

@Component({
  selector: 'my-app',
  styleUrls: ['./app.component.scss'],
  templateUrl: './app.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class AppComponent {

  get lastName() {
    console.log('CD triggered rerender')
    return 'Boodin';
  }

  buttonClick(){
    //does nothing, doesnt set any value!
  }
}
<p>{{lastName}}</p>
<button (click)="buttonClick()">Trigger Change Detection</button>
about 4 years ago · Juan Pablo Isaza
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