Angular - Services and Dependency Injection
What will happen if two components inject the same service provided in root and update a shared variable?
@Injectable({ providedIn: 'root' })
export class CounterService { count = 0; }
@Component({ ... }) export class AComponent {
constructor(private svc: CounterService) { this.svc.count++; }
}
@Component({ ... }) export class BComponent {
constructor(private svc: CounterService) { this.svc.count++; }
}