title: Saving data in angular 8 with subscribe
body: <p>Hello I have a problem with saving data in subscribe with angular 8.</p>
  
  <p>when i make this <code>this.service.getAll().subscribe(response =&gt; console.log(this.itemList = response))</code></p>
  
  <p>and print itemList the array is empty, i try to print the response in the subscribe and response have data.</p>
  
  <p>I tried to make print in subscribe and print of local array in this way :</p>
  
  <pre><code>import { Component, OnInit } from '@angular/core';
  import { Router } from '@angular/router';
  import { ItemService } from 'src/service/item.service';
  import { Item } from 'src/DTO/item';
  
  @Component({
    selector: 'app-crafting-dashboard',
    templateUrl: './crafting-dashboard.component.html',
    styleUrls: ['./crafting-dashboard.component.css']
  })
  export class CraftingDashboardComponent implements OnInit{
    itemList: Item[] = [];
  
    constructor(private router: Router, protected service: ItemService) {
    }
  
    ngOnInit() {
      this.service.getAll().subscribe(response =&gt; console.log("Reponse:" + response));
      console.log("Constrol print" + this.itemList);
    }
  
    getAll(){
  
    }
  
  }
  </code></pre>
  
  <p>i've noted that in console appear first the console.log("Constrol print" + this.itemList);
  and after the print of subscribe. It could be this the problem?!?!?</p>
  
  <p>this is my service (i made an abstract service and in the specific service I add the specific method for an entity:</p>
  
  <pre><code>import { Service } from './service';
  import { Observable } from 'rxjs';
  import { HttpClient } from '@angular/common/http';
  
  export class AbstractService&lt;DTO&gt; implements Service&lt;DTO&gt; {
      type: string = '';
      port: string = '8080';
  
      constructor(protected http: HttpClient){}
  
      getAll(): Observable&lt;DTO[]&gt; {
          return this.http.get&lt;DTO[]&gt;('http://localhost:' + this.port + '/' + this.type + '/getAll');
      }
  
      read(id: number): Observable&lt;DTO&gt; {
          return this.http.get&lt;DTO&gt;('http://localhost:' + this.port + '/' + this.type + '/read?id=' + id);
      }
  
      insert(dto: DTO): Observable&lt;DTO&gt; {
          return this.http.post&lt;DTO&gt;('http://localhost:' + this.port + '/' + this.type + '/insert', dto);
      }
  
      update(dto: DTO): Observable&lt;DTO&gt; {
          return this.http.put&lt;DTO&gt;('http://localhost:' + this.port + '/' + this.type + '/update', dto);
      }
  
      delete(id: number): Observable&lt;any&gt; {
          return this.http.delete('http://localhost:' + this.port + '/' + this.type + '/delete?id=' + id);
      }
  
  
  }
  </code></pre>
  
  <p>The back-end is written in java with spring</p>