Angular - ComponentsWhy does Angular call ngOnChanges before ngOnInit when a component has input properties?ABecause ngOnInit depends on ngAfterViewInit to complete firstBTo provide the component with the initial input property values before initializationCTo delay initialization until all child components are readyDBecause ngOnChanges is only called once after the component is destroyedCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand input property flowAngular sets input properties and calls ngOnChanges to notify the component of changes.Step 2: Initialization orderngOnChanges runs before ngOnInit to ensure the component has the latest input values before initialization.Final Answer:To provide the component with the initial input property values before initialization -> Option BQuick Check:ngOnChanges runs first to update inputs [OK]Quick Trick: ngOnChanges runs first to update inputs [OK]Common Mistakes:Thinking ngOnInit runs firstConfusing with view hooksMisunderstanding ngOnChanges timing
Master "Components" in Angular9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Angular Quizzes Angular Modules - Shared modules for reusable components - Quiz 8hard Angular Modules - Module lazy loading preview - Quiz 10hard Angular Modules - Module lazy loading preview - Quiz 6medium Component Interaction - @ContentChild and content projection - Quiz 3easy Component Interaction - Template reference for direct access - Quiz 3easy Directives - *ngSwitch for multiple conditions - Quiz 13medium Directives - ngClass for dynamic classes - Quiz 6medium Lifecycle Hooks - ngOnDestroy for cleanup - Quiz 5medium Pipes - Creating custom pipes - Quiz 7medium Templates and Data Binding - Template reference variables - Quiz 7medium