As others have said, use a service.
I have a simple example here:
https://blogs.msmvps.com/deborahk/build-a-simple-angular-service-to-share-data/
import { Injectable } from ‘@angular/core’;
@Injectable()
export class DataService {
serviceData: string;
}
Or now in Angular v6 and higher:
import { Injectable } from ‘@angular/core’;
@Injectable({
providedIn: 'root'
})
export class DataService {
serviceData: string;
}