title: How to fetch all data from ngFor? Is any restrictions for fetching data into table with ngFor?
body: <p>I have a Component which should create a record in DB through Service.</p>
  
  <pre><code>@Component({
    selector: 'app-add-company',
    templateUrl: './add-company.component.html',
    styleUrls: ['./add-company.component.css']
  })
  export class AddCompanyComponent implements OnInit {
  
  formItem: Company = new Company();
  savedItem: Company;
  formGroup: FormGroup;
  
  constructor(private companyService: CompanyService, private router: Router, private formBuilder: FormBuilder) {}
  
  ngOnInit() {
      this.formGroup = this.formBuilder.group({
          publicName:new FormControl('', Validators.compose ([Validators.required, Validators.minLength(2)]))
  
      });
  
  
  }
  
  saveForm(item: Company) {
  
      this.savedItem = this.companyService.saveCompany(item);
  
      console.log("Print form object - log from component - : " + item)
      console.log("Print returned object from service - log from component - : " + this.savedItem)
      console.log("Print returned ID of object from service - log from component - : " + this.savedItem.id)
  
      if (this.savedItem.id) {
          console.log("New Company has been created with ID : " + this.savedItem.id + "and name : " + this.savedItem.publicName);}
      else console.log("Company hasn't been created");
  
      //this.router.navigateByUrl('lead/company/${this.savedItem.id}');
  
  }
  </code></pre>
  
  <p>I am sending this form item to service. Service, in its turn, sends data to DB through other service and application server. Everything works as expected.</p>
  
  <pre><code>@Injectable()
  export class CompanyService {
  
  itemUrl = "company";
  object: Company = new Company();
  private items: Company[] = new Array&lt;Company&gt;();
  //private groups: string[] = [];
  
  constructor(private repository: RestRepository) {
      repository.getAllData(this.itemUrl).subscribe(data =&gt; this.items = data );
  }
  
  getAllCompanies(): Company[] {
      return this.items;
  }
  
  saveCompany(item: Company) {
      if (item.id == undefined || item.id == null) {
          this.repository.saveData(this.itemUrl, item).subscribe(i =&gt; {
          this.items.push(i);
  
          this.object = i;
          console.log("Print a subscribed object - log from service - : " + this.object.publicName + "  ID " + this.object.id)
  
          });
          let pop = this.items.pop();
          console.log("Print an array with pop() - log from service - : " + pop.publicName + "  ID " + pop.id)
  
  
      } else {
          return this.repository.updateData(this.itemUrl, item).subscribe(i =&gt; {
              this.items.splice(this.items.findIndex(i =&gt; i.id == item.id), 1, item);
              this.items.push(i);
          });
      }
  }
  </code></pre>
  
  <p>I got this code from the book, and author didn't ask for return object after saving it. I need this object for my cases.
  So the problem is that Service does all that it should, but doesnt wait till "i" variable from subscribe method will be pushed to an array and attached to another variable. Those steps happened but after the return statement will be invoked. 
  So I can't receive a saved object from db inside Component.</p>
  
  <p>Can you hint please, how can I write this method properly. </p>
  
  <ol>
  <li>Assuming, I somehow should write a callback function here, but I
  don't know how. </li>
  <li>Or maybe there is an another decision, more
  elegant?
  In result, I need to return a saved item back to Component.</li>
  </ol>
  
  <p>This is console.log(). Before I saved an item "Apple Inc", next item was "Stack Overflow".</p>
  
  <pre><code>Print an array with pop() - log from service - : Apple Inc  ID 5929da7f7b99e80c09124859
  add-company.component.ts:35 Print form object - log from component - : [object Object]
  add-company.component.ts:36 Print returned object from service - log from component - : undefined
  AddCompanyComponent.html:2 ERROR TypeError: Cannot read property 'id' of undefined
  Print a subscribed object - log from service - : Stack Overflow   ID 5929dae37b99e80c0912485a
  </code></pre>