Question 1 / 1
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) {}
}