Simplest way to share data between two unrelated Components in Angular | Infragistics Blog

PHOTO EMBED

Fri Sep 22 2023 05:53:10 GMT+0000 (Coordinated Universal Time)

Saved by @dayalalok #angular

import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
 
@Injectable({
    providedIn: 'root'
})
export class AppService {
    counter = 1;
    count: BehaviorSubject<number>;
    constructor() {
 
        this.count = new BehaviorSubject(this.counter);
    }
 
    nextCount() {
        this.count.next(++this.counter);
    }
}
content_copyCOPY

UnrelatedComponentCommunications

https://www.infragistics.com/community/blogs/b/infragistics/posts/simplest-way-to-share-data-between-two-unrelated-components-in-angular