title: passing data from one typescript file to another in angular
body: <p>I have A component which has the following template</p>
  
  <pre><code>&lt;div&gt; This is A component &lt;/div&gt;
      &lt;router-outlet&gt;&lt;/router-outlet&gt; 
  </code></pre>
  
  <p>If I use url </p>
  
  <blockquote>
    <p>site.com/A/B</p>
  </blockquote>
  
  <p>then angular loads A component and puts B inside A's template.</p>
  
  <p>A component has: </p>
  
  <pre><code>export class SettingsComponent implements OnInit {
    someVar;
  
   ngOnInit() {
  this.someVar = "TEST"
  </code></pre>
  
  <p>How can I get this variable while starting B component ???</p>
  
  <p><strong>EDIT</strong> I don't want to use service for each of them because that TEST I get from API. And I think I will load server twice with such request. Instead of that I want to get it only once. Like in this example suppose I get reply from server and put it inside <code>this.someVar = "TEST"</code> So second component should only use first component data not touching the backend server API.</p>