Angular - Component InteractionYou have two unrelated Angular components that need to share user login status. Which approach is best to communicate this data?AUse a shared service with an observable to hold and broadcast the login status.BPass data directly using @Input() and @Output() between the two components.CUse local variables inside each component without communication.DUse template reference variables to share data between components.Check Answer
Step-by-Step SolutionSolution:Step 1: Identify component relationshipUnrelated components do not have parent-child relation, so @Input/@Output won't work.Step 2: Choose communication methodA shared service with an observable allows broadcasting data to any component.Final Answer:Use a shared service with an observable to hold and broadcast the login status. -> Option AQuick Check:Unrelated components communicate via shared service [OK]Quick Trick: Use shared service for unrelated component communication [OK]Common Mistakes:Trying to use @Input/@Output between unrelated componentsUsing local variables that don't share dataMisusing template reference variables for communication
Master "Component Interaction" in Angular9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Angular Quizzes Angular Fundamentals - Why Angular for enterprise applications - Quiz 1easy Angular Modules - Module lazy loading preview - Quiz 9hard Angular Modules - Shared modules for reusable components - Quiz 5medium Components - Component styles and encapsulation - Quiz 7medium Components - Why components are the building blocks - Quiz 15hard Directives - Why directives are needed - Quiz 15hard Directives - *ngIf for conditional rendering - Quiz 6medium Lifecycle Hooks - ngOnDestroy for cleanup - Quiz 11easy Pipes - Pipe performance considerations - Quiz 6medium Templates and Data Binding - Two-way binding with ngModel - Quiz 8hard