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

209
Visualizações
ngmodel not working in child component for on push change detection

I am creating my custom component, suppose api response is late(here I reproduced problem with setTimeOut()), then my ngModel is not updating until I select that component, I am using ChangedetectionStratagy OnPush

Here I am attaching stackblitz link directly . Please help

https://stackblitz.com/edit/primeng-dropdown-demo-2t9ed3?file=src/single-select/single-select.component.ts

It is working fine when I am making ChangedetectionStratagy.Default

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

0

Well since you are using onPush change detection strategy you have to trigger the change detection manually . with onPush the change detection is not trigger until component input changes. here is how you trigger it manually in your AppComponent

export class AppComponent implements OnInit {
 constructor(private cf: ChangeDetectorRef) {} // insert changeDetectorRef
  ngOnInit() {
   setTimeout(() => {
    this.selectedModel = 'CN';
    this.cf.markForCheck() // line added
   }, 2000);
  }

https://stackblitz.com/edit/primeng-dropdown-demo-jbzchf?file=src/single-select/single-select.component.html

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