12 March 2021

toPromise() Angular 2 (async await)

 

#1 Async Short - ToPromise

2021

const data = await this.chatManagementService.getBots().toPromise();
console.log(data);

#2 Async Function - ToPromise

2021
async ngOnInit() {
    await this.getBots();
}
/**
 * Async function
 * GET ALL BOT
 */
private async getBots(): Promise < void > {
    await this.chatManagementService.getBots()
    .toPromise()
    .then(value => {
        console.log(value)
    })
    .catch(error => console.log(error));
}

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang