Angular - Passing of attributes from the Father to the Son with consultation.

0

I'm a beginner in Angular and I have a seemingly simple problem. I have a service that returns me a Promise:

  public getNFE(numero: string): Promise<Nfe>{
return this.http.get('${URL_API}nfe?numeroNfe=${numero}')
  .toPromise()
  .then(response => response.json()); }

I have a component that serves as a page (Base for other components):

export class PaginaInicialComponent implements OnInit {

  private nfe: Nfe;

  constructor(private service: NfeService) { 
    console.log("Constructor (Main):");
    this.service.getNFE('26180406057223028939650050000133071050336085')
    .then((nfe: Nfe) => {
      this.nfe = nfe;
      console.log("Constructor dentro (Main):");
      console.log(nfe);
    })
  }

  ngOnInit() {
    console.log("OnInit (Inicio Main):");

    console.log("OnInit (Fim Main):");
  }

}

This same component (HomePage) calls another:

<app-painel-nfe [nfe]='nfe'></app-painel-nfe>

Let's go to the problem, the value of NFE is not arriving at this other component (app-panel-nfe) since the query la no service takes a minimum time, it is as if the Angular did not wait for the result and immediately called the other component . That way when this component is created I never have the information.

Does anyone know how to help me with this?

    
asked by anonymous 04.05.2018 / 02:50

0 answers