1. 9
    Notify Users Their Database Operation Worked with a Toast Alert
    2m 14s

Notify Users Their Database Operation Worked with a Toast Alert

Jorge Vergara
InstructorJorge Vergara
Share this video with your friends

Social Share Links

Send Tweet
Published 2 years ago
Updated 2 years ago

We'll evaluate 2 good practices when adding a new task.

First, we'll show the users a toast alert to notify them that their document was saved in the database. We'll do this with a toast component that ionic makes available to us

And second, we'll use Angular's router to navigate the user back to the task list.

[0:01] Instructor: Now we need a way to notify our users that the task was indeed created. For that we are going to do two things. First, we are going to display a toast to our user saying that everything worked as expected. Second, we are going to redirect our user to the tasks page.

[0:19] For redirecting our users, I'm going to import here the router from Angular router. For alerting our users, I'm going to use one of Ionic's alerts and it's called the toast controller. We import that one from Ionic Angular.

[0:42] Now that we have them here, I'm going to extract the toast functionality into a helper function. This is going to take a message as a parameter. I'm going to give it a default value of task successfully updated.

[1:02] Here, I'm going to create the toast and I'm going to pass on parameter. First is the message. Second, it asks me for the duration. Let's say this is going to be two and a half seconds. Then is the position. We want to have this at the bottom of the screen. Lastly is the color.

[1:29] I'm using one of Ionic color variables called success. This is like a green color. Then once we successfully update the document, I'm going to call the present toast function.

[1:42] Then I'm going to use the Angular router to navigate back to the tasks page. After creating the toast, I have to actually present it. Now, I can go back to create a new task.

[2:02] When I click save task, now I'm going to get my notification task successfully created. In here, I can see all of the tasks that I have created.

egghead
egghead
~ 13 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today