Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!