>

CODEMASTERYLAB

IDE PLATFORM
CoursesCommunity BlogsKnowledge GraphQuizzesInterview Prep

Sign in to track progress & earn XP

Sign In Create Account
>
Code Mastery Lab

Code Mastery Lab

Sign In

Services and Dependency Injection — Building the Singleton Layer

Question 1 / 1

0:00
Core
Medium

Your app has a NotificationService decorated with @Injectable({ providedIn: 'root' }) that stores an array of notifications. A HeaderComponent and a SidebarComponent both inject NotificationService. When HeaderComponent adds a notification, SidebarComponent does not reflect the change. What is the most likely cause?

typescript @Component({ selector: 'app-sidebar', providers: [NotificationService], // <-- note this line template: <div *ngFor="let n of service.notifications">{{ n }}</div> }) export class SidebarComponent { constructor(public service: NotificationService) {} }