title: Angular 2 this.data is undefined
body: <p>I'm trying to read the content of my JSON file through my "GetJsonService".</p>
  
  <p><strong>app.component.ts:</strong></p>
  
  <pre><code>data: any;
  
  constructor(private jsonService: GetJsonService) {}
  
  ngOnInit() {
      this.getRecords();
      console.log(this.data);
  }
  
  getRecords() {
      this.jsonService.getRecords().subscribe(data =&gt; {
          this.data = data;
      }, err =&gt; {
          console.log(err);
      });
  }
  </code></pre>
  
  <p><strong>get-json.service.ts</strong></p>
  
  <pre><code>constructor(private http: Http) { }
  
  data: any;
  
  getRecords() {
      return this.http.get('assets/standorte.json').map(data =&gt; {
          this.data = data.json();
          return data.json();
      }, err =&gt; {
          if (err) {
              return err.json();
         }
       });
   }
  </code></pre>
  
  <p>I want to put the content of data.json() into this.data to use it.
  But when I log this.data it is "undefined".</p>
  
  <p>I'm completely new to Angular 2 and Typescript, so I really would be thankful when someone helps me.</p>
  
  <p>Greetings</p>