I am creating a LoadingController
below, presenting it, & executing some methods:
this.loadingCtrl.create({
message: 'Sending Message...'
}).then(loadingEl => {
loadingEl.present();
this.conversationsService.addMessageToConversation(this.conversation.id, this.form.value.message);
this.loadMsg();
this.form.reset();
});
Once addMessageToConversation()
is successfuly, I then want to dismiss
the LoadingController.
Can someone please tell me how I can do this?
Here is addMessageToConversation()
in case it is required:
addMessageToConversation(conversationId: string, message: string) {
this._conversations.getValue().find(conversation => conversation.id === conversationId)
.messages.push(
new Message(
Math.random().toString(),
message,
this.authService.userId,
new Date(Date.now())
));
}
There are two ways to do this.
I'd suggest using Method #2 as that is "normal". Once your turn the service's method into a promise you can adjust your code as follows:
this.loadingCtrl.create({ message: 'Sending Message...' }).then(async loadingEl => { loadingEl.present(); const res = await this.conversationsService.addMessageToConversation(this.conversation.id, this.form.value.message); this.loadMsg(); this.form.reset(); this.loadingCtrl.dismiss() });
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.