1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Use async/await in ngOnInit method will influence for life cycle hooks

Discussão em 'Angular' iniciado por wiki, Setembro 24, 2024.

  1. wiki

    wiki Guest

    I am developing a web site by using Angular/.Net core.

    I am using async/await in ngOnInit() method to await the results.

    async ngOnInit() {

    let response= await this.loginservice.availabilities(this._searchinfo).toPromise();

    console.log("no of units");
    }

    ngAfterViewInit() {

    console.log("Call ngAfterViewInit");
    }


    Though I used await/async, the system called ngAfterViewInit() method before returning the results from ngOnInit(). That means, If I check the console, I can see below readings from the console

    Call ngAfterViewInit
    no of units


    How is this possible?. When using await/async, isn't it going to block other life cycle hooks?

    Thanks in advance.

    Continue reading...

Compartilhe esta Página