I wasn't sure if the response from @Zircon was exactly what you needed, so I'll provide my approach to address your query.
If you've already imported your service in app.module.ts and included it in the list of providers, you can structure your service like this:
import { BehaviorSubject } from 'rxjs/Rx';
import { Injectable } from '@angular/core';
@Injectable()
export class YourService {
public var1: BehaviorSubject<string> = new BehaviorSubject('str');
public var2: BehaviorSubject<boolean> = new BehaviorSubject(true);
public var3: BehaviorSubject<number> = new BehaviorSubject(123);
When a component modifies any of these values, other components can stay synchronized by implementing something similar within their respective components:
export class YourComponent implements OnInit {
myData: any = this.yourService.var1.subscribe((value) => this.myData = value);
constructor(
private yourService: YourService) { }
ngOnInit() {
}
}
To update values, you can do:
this.yourService.var1.next('new_str');
If you want certain components to automatically update your service variables when they load, you can include the above line within the ngOnInit(){}
block.