Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Commonmark migration
Fonte Link

Tenho duas funções assíncronas A e B.

 

Como faço para inicializar a função B apenas depois que a função A esteja completa?

import { Component } from '@angular/core';

import { Options } from 'fullcalendar';
import { DataService } from './services/data.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

  data: Data[] = [];

  calendarOptions: Options;

  constructor(private dataService: DataService){}

  ngOnInit() {
    const var1 = await this.A();
    const var2 = await this.B();
  }


  async A(){
      this.dataService.getItems().subscribe(items => {
        items.forEach(item => {
          this.data.push(item);
        })
      });

  }

  async B(){
      this.calendarOptions = {
        editable: true,
        eventLimit: false,
        header: {
          left: 'prev,next today',
          center: 'title',
          right: 'month,agendaWeek,agendaDay,listMonth'
        },
        defaultDate: '2017-11-23',
        navLinks: true,
        events: [{
            id:1,
            title:this.data[0].title,
            start:"2017-11-23 09:00:00",
            end:"2017-11-23 11:00:00",
            color:"#0071c5"
        }]
      };

  }
}

Tenho duas funções assíncronas A e B.

 

Como faço para inicializar a função B apenas depois que a função A esteja completa?

import { Component } from '@angular/core';

import { Options } from 'fullcalendar';
import { DataService } from './services/data.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

  data: Data[] = [];

  calendarOptions: Options;

  constructor(private dataService: DataService){}

  ngOnInit() {
    const var1 = await this.A();
    const var2 = await this.B();
  }


  async A(){
      this.dataService.getItems().subscribe(items => {
        items.forEach(item => {
          this.data.push(item);
        })
      });

  }

  async B(){
      this.calendarOptions = {
        editable: true,
        eventLimit: false,
        header: {
          left: 'prev,next today',
          center: 'title',
          right: 'month,agendaWeek,agendaDay,listMonth'
        },
        defaultDate: '2017-11-23',
        navLinks: true,
        events: [{
            id:1,
            title:this.data[0].title,
            start:"2017-11-23 09:00:00",
            end:"2017-11-23 11:00:00",
            color:"#0071c5"
        }]
      };

  }
}

Tenho duas funções assíncronas A e B.

Como faço para inicializar a função B apenas depois que a função A esteja completa?

import { Component } from '@angular/core';

import { Options } from 'fullcalendar';
import { DataService } from './services/data.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

  data: Data[] = [];

  calendarOptions: Options;

  constructor(private dataService: DataService){}

  ngOnInit() {
    const var1 = await this.A();
    const var2 = await this.B();
  }


  async A(){
      this.dataService.getItems().subscribe(items => {
        items.forEach(item => {
          this.data.push(item);
        })
      });

  }

  async B(){
      this.calendarOptions = {
        editable: true,
        eventLimit: false,
        header: {
          left: 'prev,next today',
          center: 'title',
          right: 'month,agendaWeek,agendaDay,listMonth'
        },
        defaultDate: '2017-11-23',
        navLinks: true,
        events: [{
            id:1,
            title:this.data[0].title,
            start:"2017-11-23 09:00:00",
            end:"2017-11-23 11:00:00",
            color:"#0071c5"
        }]
      };

  }
}
Fonte Link

Como encadear funções async no typescript?

Tenho duas funções assíncronas A e B.

Como faço para inicializar a função B apenas depois que a função A esteja completa?

import { Component } from '@angular/core';

import { Options } from 'fullcalendar';
import { DataService } from './services/data.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

  data: Data[] = [];

  calendarOptions: Options;

  constructor(private dataService: DataService){}

  ngOnInit() {
    const var1 = await this.A();
    const var2 = await this.B();
  }


  async A(){
      this.dataService.getItems().subscribe(items => {
        items.forEach(item => {
          this.data.push(item);
        })
      });

  }

  async B(){
      this.calendarOptions = {
        editable: true,
        eventLimit: false,
        header: {
          left: 'prev,next today',
          center: 'title',
          right: 'month,agendaWeek,agendaDay,listMonth'
        },
        defaultDate: '2017-11-23',
        navLinks: true,
        events: [{
            id:1,
            title:this.data[0].title,
            start:"2017-11-23 09:00:00",
            end:"2017-11-23 11:00:00",
            color:"#0071c5"
        }]
      };

  }
}