Reddit Inspired Upvoting System with Angular and Firebase NoSQL
Key Takeaways
This video demonstrates how to build a Reddit-style upvoting system using Angular 4 and Firebase NoSQL database, including data modeling, service creation, and component development.
Full Transcript
in this episode we're going to build a Reddit style up voting down voting system using angular 4 and Firebase in this example we have a collection of items already in the database and we also have Firebase authentication set up in our app if you're new to Firebase authentication I've added a couple links in the description with more details the first thing we need to think about is modeling our data in the Firebase no SQL database our database needs to answer two fundamental questions what is the user's vote for a given item and What's the total vote count for a given item we can answer this question by creating a collection based on the unique ID of the items for each item id we save the user IDs that have voted on that item this way we can query an item and see if the users voted on it and we can also tally up the collection of users under an item to get the total vote account let's start by building the service the first thing we need is the Firebase object observable for a specific item [Music] id we also need the user to be able to cast their vote by updating the item object in the database the update user vote function will send a new key value pair to the the item in the database with the key being the user's ID and the value being the value of the boat which can be either A-1 zero or one now we can build the upvote button component our component will accept a couple of input values since this is normally going to be a child component of an item we can go ahead and pass it the item id as well as the user ID in the component typescript we have just a generic component but we're also going to be using the input decorator and we've also imported low Dash as well to help us facilitate the vote count which you'll see later on so we have input variables for the item ID and the user ID and we have a couple number variables one that represents the total vote count and one that represents the current user's vote during the NG on AIT life cycle hook we can subscribe to the Firebase object observable from our service the observable itself is going to emit the up votes and we can use that to figure out what the user's vote is and also get the total vote count for an item and we add a conditional statement when checking the user vote because it's possible the user is not logged in when viewing an item an added feature you might consider is redirecting the user to a loog Lo in page when they click the up vote button and they're not logged in in this example I'm using the low Dash library to put all the object values into an array and then get the sum of that array doing the same thing in JavaScript would require a lot more code so we're going to keep it concise and readable so now we can build two separate functions one for up boting and one for down boting these functions are identical the only difference being a positive one for an up vote and a netive one for a down vote we also want the user to be able to cancel their vote by just clicking the same button again so we do this by checking to see if the user vote is already an up Vote or a down vote and if it is then we set the vote value to zero which will essentially reverse their vote we can do this in one line using a JavaScript turn are operator to replace a multi-line if El statement the final step is to end the subscription once the component's destroyed to avoid introducing memory leaks into the app we can do this with the on destroy life cycle [Music] [Music] hook in the template we create two Arrow icons that handle up boating and down boating we simply find the up vote and down vote functions to The Click event on these buttons [Music] in order to show the user whether or not they've up voted or down voted for an item we color the up votes green and the down votes red we can do this with the NG class directive which will add an active class to the item if it's up vat is either greater than zero or less than zero now if we go into our app we can see that we have a fully functional upboat downb system on the left we have the app itself and on the right we can see it's updating the Firebase database in real [Music] time that's it for this episode if you found the video helpful please like And subscribe and if you want to support the channel consider becoming a pro subscriber at angular firebase.com for just a few bucks a month you'll get access to exclusive content as well as free one-on-one project Consulting thanks for watching and I'll see you next time audio jum
Original Description
https://angularfirebase.com/lessons/reddit-style-upvoting-in-angular-4-and-firebase-nosql/
Learn how to build a Reddit-style upvote/downvote system with Angular 4 and Firebase Realtime NoSQL database.
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Fireship · Fireship · 13 of 60
1
2
3
4
5
6
7
8
9
10
11
12
▶
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Angular 4 Development and Production Environments with Firebase
Fireship
OAuth with Angular and Firebase Tutorial
Fireship
Anonymous Authentication with Angular and Firebase - Lazy Registration
Fireship
Angular Router Guards for Firebase Users
Fireship
Angular Firebase CRUD App with NoSQL Database Tutorial
Fireship
Upload Files from Angular to Firebase Storage
Fireship
How to Deploy an Angular App to Firebase Hosting
Fireship
Sharing Data between Components in Angular
Fireship
Loading Spinners for Asynchronous Firebase Data
Fireship
Angular 4 Transactional Email with Google Firebase Cloud Functions
Fireship
Firebase Database Rules Tutorial
Fireship
Autocomplete Search with Angular4 and Firebase
Fireship
Reddit Inspired Upvoting System with Angular and Firebase NoSQL
Fireship
Angular Drag-and-Drop File Uploads to Firebase Storage
Fireship
Text Translation with Firebase Cloud Functions onWrite and Angular 4
Fireship
Custom Usernames with Firebase Authentication
Fireship
Twitter-Inspired Follow Unfollow Feature with Firebase and Angular 4
Fireship
Simple Pagination with Firebase and Angular 4
Fireship
How to Connect Firebase Users to their Data - 3 Methods
Fireship
Add Toast Message Notifications to your Angular App
Fireship
Facebook-Inspired Reactions System with Angular and Firebase
Fireship
Learn NgModule in Angular with Examples
Fireship
Lazy Loading Components in Angular 4
Fireship
Stripe Checkout Payments with Angular and Firebase - Part 1
Fireship
Process Stripe Payments with Firebase Cloud Functions - Part 2
Fireship
Selling Digital Content in Angular with Stripe Payments - Part 3
Fireship
Angular 4 Full Text Search with Algolia - Part 1
Fireship
Algolia with Firebase Cloud Functions - Part 2
Fireship
Firebase Phone Authentication in Angular 4
Fireship
Top 7 RxJS Concepts for Angular Developers
Fireship
Learn Angular Animations with 5 Examples
Fireship
Advanced Firebase Data Filtering (Multi-Property)
Fireship
Realtime Maps with Mapbox + Firebase + Angular
Fireship
Angular Reactive Forms with Firebase Database Backend
Fireship
Send Push Notifications in Angular with Firebase Cloud Messaging
Fireship
Top 7 Ways to Debug Angular 4 Apps
Fireship
Infinite Scroll with Angular and Firebase
Fireship
Use TypeScript with Firebase Cloud Functions
Fireship
Realtime Graphs and Charts with Plotly and Firebase
Fireship
Role-Based User Permissions in Firebase
Fireship
User Presence System in Realtime - Online, Offline, Away
Fireship
Location-based Queries with GeoFire and Angular Google Maps
Fireship
Angular ngrx Redux Quick Start Tutorial
Fireship
Angular Ngrx Effects with Firebase Database
Fireship
Progressive Web Apps with Angular
Fireship
Angular Ngrx with Firebase Google OAuth User Authentication
Fireship
RxJS Quick Start with Practical Examples
Fireship
Send SMS Text Messages with Twilio and Firebase
Fireship
Firebase Database Performance Profiling
Fireship
Native Desktop Apps with Angular and Electron
Fireship
Subscription Payments with Stripe, Angular, and Firebase
Fireship
Firestore with AngularFire5 Quick Start Tutorial
Fireship
Angular HTTP Client Quick Start Tutorial
Fireship
Google Sign-In with Firestore Custom User Data
Fireship
Star Review System from Scratch with Firestore + Angular
Fireship
Angular Chatbot with Dialogflow (API.ai)
Fireship
Learn @ngrx/entity and Feature Modules
Fireship
Infinite Scroll Pagination with Firestore
Fireship
Faster Firestore via Data Aggregation
Fireship
Contentful - CMS for Angular Progressive Web Apps
Fireship
More on: Database Integration
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Müşteri Değerini Anlamak: RFM, CLTV ve Tahmine Dayalı CRM Analitiği
Medium · Machine Learning
Müşteri Değerini Anlamak: RFM, CLTV ve Tahmine Dayalı CRM Analitiği
Medium · Data Science
Müşteri Değerini Anlamak: RFM, CLTV ve Tahmine Dayalı CRM Analitiği
Medium · Python
Surviving the Data Science Behavioral Interview
Towards Data Science
🎓
Tutor Explanation
DeepCamp AI