Fireship · @fireship
Add Toast Message Notifications to your Angular App
Uploaded July 4, 2017 · Length 4:27
Summary
Add toast message notifications to an Angular app using Firebase and Bulma CSS.
- angular toast notifications
- firebase database
- bulma css
- angular services
- toast messages
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
in this episode we're going to build
- 0:02
toast style notification messages from
- 0:04
scratch the messages will be saved on
- 0:06
the back end in Firebase as well so we
- 0:09
can maintain a full history of the
- 0:10
messages that have been sent the
- 0:12
messages are managed by a central
- 0:14
service that can be injected into any
- 0:16
component this makes it possible to
- 0:18
trigger messages from anywhere in the
- 0:20
app on the front end we're using the
- 0:23
Bulma CSS framework but you could easily
- 0:25
Swap this out for bootstrap or material
- 0:28
or your own custom classes
- 0:31
let's start by building the toast
- 0:32
service we'll first start by importing
- 0:36
the angular fire database then we'll
- 0:38
create a custom message class just to
- 0:40
model our data a message can have a
- 0:43
Content as a string a style and it can
- 0:46
also be dismissed which is a Boolean
- 0:48
value in the Constructor we send it the
- 0:50
content and an optional style argument
- 0:53
if the style is undefined it'll just
- 0:55
default to
- 0:57
info in the service we create a function
- 0:59
to return the Firebase list observable
- 1:02
with the messages in the database we
- 1:04
want to limit this query to the last
- 1:06
five
- 1:07
messages from there we create a function
- 1:10
to create a new message this function
- 1:12
can be called anywhere from any
- 1:14
component and it'll update the Firebase
- 1:16
list
- 1:17
observable it simply takes the content
- 1:20
and style as arguments and builds a new
- 1:22
message and sends that to the
- 1:24
database and the last step is to give
- 1:27
the user the ability to dismiss messages
- 1:29
so we just retrieve a message as an
- 1:31
object and then update its dismissed
- 1:34
attribute to
- 1:37
True before we start building the
- 1:39
component I'm going to build a custom
- 1:41
pipe that will filter out the dismissed
- 1:43
messages and then send them in reversed
- 1:45
order so they display one on top of the
- 1:48
other first I import the filter and
- 1:51
reverse functions from low Dash and the
- 1:54
value going into this pipe will be an
- 1:55
array of messages so we can call reverse
- 1:59
and then we can fill filter out the


