Fireship · @fireship

Twitter-Inspired Follow Unfollow Feature with Firebase and Angular 4

Uploaded June 27, 2017 · Length 5:48

Twitter-Inspired Follow Unfollow Feature with Firebase and Angular 4

Summary

build follow unfollow feature with firebase and angular 4 similar to twitter

  • firebase angular 4
  • follow unfollow feature
  • angular firebase tutorial
  • twitter inspired feature

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    in this episode we're going to build a

  2. 0:02

    follow unfollow feature similar to

  3. 0:04

    Twitter using angular for on the front

  4. 0:06

    end and firebase no sequel on the back

  5. 0:09

    end in order to get started with this

  6. 0:11

    lesson you'll need to have firebase

  7. 0:13

    authentication already wired up in your

  8. 0:15

    angular app if you don't have that done

  9. 0:17

    check out the link in the top right

  10. 0:19

    corner for a lesson completely dedicated

  11. 0:21

    to authentication let's start by

  12. 0:24

    modeling the data in a standard sequel

  13. 0:27

    database you could setup a many-to-many

  14. 0:28

    relationship but since we're dealing

  15. 0:30

    with no sequel we have to do things a

  16. 0:32

    little differently the database needs to

  17. 0:35

    answer two fundamental questions first

  18. 0:37

    is the current user following any other

  19. 0:40

    given user and second what is a user's

  20. 0:43

    follower account the first question can

  21. 0:46

    be answered by saving a user's followers

  22. 0:48

    under their own user ID and the second

  23. 0:51

    question can be answered by doing the

  24. 0:53

    exact opposite saving each followed user

  25. 0:56

    ID under their own user ID let's start

  26. 1:00

    putting this together in a service that

  27. 1:01

    will call the Qualla service first we

  28. 1:06

    import the angularfire to database then

  29. 1:12

    we create a function to get a user's

  30. 1:14

    followers this will be used primarily to

  31. 1:16

    build the follower Cal it simply

  32. 1:19

    requests the database object based on

  33. 1:22

    the user ID that's passed as an argument

  34. 1:25

    next we create a function that will tell

  35. 1:27

    us whether or not user a is following

  36. 1:29

    user being

  37. 1:31

    it gets passed to user IDs its arguments

  38. 1:34

    and will query the database for that

  39. 1:36

    specific key value pair if it returns

  40. 1:40

    true we know that that relationship

  41. 1:41

    exists and if it returns null then we

  42. 1:44

    know that that user is not following the

  43. 1:46

    other user from there we can start

  44. 1:50

    building our follow function which will

  45. 1:53

    update the database with the

  46. 1:55

    relationship when the user decides to

  47. 1:57

    follow another user this will make two