(accordion) Should use ngAfterContentInit for better performance ?
See original GitHub issueI just realize NgbAccordion
use ngAfterContentChecked
to populate initial state:
https://github.com/ng-bootstrap/ng-bootstrap/blob/master/src/accordion/accordion.ts#L178
This is not good for performance, because ngAfterContentChecked
will be triggered in every change detection.
Maybe I missed something, but I think we should use ngAfterContentInit
instead of ngAfterContentChecked
.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Angular2: @ContentChild - only immediate children
@ContentChildren( myTitle, {descendants: false}) myTitle: QueryList<myTitle>; ngAfterContentInit() { console.log(this.myTitle.
Read more >Angular Lifecycle Hooks: ngOnChanges, ngOnInit, and more
ngDoCheck fires with every change detection cycle. Angular runs change detection frequently. Performing any action will cause it to cycle.
Read more >Accordion Test in blogger
Accordion Test in blogger · 1. It is entirely component based. · 2. Better change detection · 3. Angular2 has better performance. ·...
Read more >Accordion | carbon-components-angular
ngAfterContentInit · updateChildren. Properties. Protected _skeleton. _skeleton: boolean = false. Defined in src/accordion/accordion.component.ts:36 ...
Read more >AfterContentInit - Angular
A lifecycle hook that is called after Angular has fully initialized all content of a directive. Define an ngAfterContentInit() method to handle any...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is not enough as
closeOthers
needs to be taken into account as well. So it would have to be a setter. Same goes for any property that influences internal state of the accordion. Multiplying those setters results in code that is super-hard to maintain.Given this I would much rather focus on making this component
OnPush
which would have even better perf characteristics. But then again, I’m not sure if this is priority unless we’ve got real-life proof of thengAfterContentChecked()
method in accordion being a perf bottleneck.Cleaning up issues in preparation for 1.0 release so I’m going to close this one for now. Please comment back / open a new issue if anything is not performing as expected in real-life applications.