ChangeDetectorRef’s detectChanges doesn’t trigger changedetection

I want to create an accordion component. There should be only one tab opened at the time. Everything works fine, until I change the changeDetection to ChangeDetectionStrategy.OnPush. I’m calling the detectChanges method, but somehow it doesn’t trigger changeDetection.

My design of the accordion looks like this:

  • AccordionTabComponent is the child, it knows whether the tab is opened, or closed. Through forwardRef he can call parents closeOthers method.
  • AccordionComponent is the parent component. Through @ContentChildren it knows about child tabs and it manages the closing/opening behavior.
  • when user opens a tab by clicking, the child calls closeOthers parent method with id of currently opened one. When parent component closes all opened tabs, calls the detectChanges. It should trigger the change-detection and update the DOM. But this last thing doesn’t happen.

I’m not sure what causing this, maybe it’s because of <ng-content>?

Stackblitz example.

Source: Angular

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.