Top 7 Ways to Debug Angular 4 Apps

Fireship · Beginner ·📰 AI News & Updates ·8y ago

Key Takeaways

The video discusses seven techniques for debugging Angular 4 applications, including using TypeScript, debugger statements, JSON pipes, Angular's built-in debugging tools, the Augury plugin, custom loggers, and RxJS debugging methods.

Full Transcript

debugging is easily one of the most annoying and frustrating aspects of a programmer's life in this episode I'm going to cover seven different techniques that you can use to debug angular 4 applications hopefully this will save you some time and frustration as you build your app the great thing about angular is that it uses typescript by default which prevents many of the bugs that plague JavaScript applications it does this by allowing you to write JavaScript code with static typing as opposed to Dynamic typing this just means you define the data types and properties of object before they're actually used in the code so why is this beneficial well the number one reason is it allows your text editor to give you instant feedback whenever you're about to introduce a bug into your code take a look at this code here it's more or less just plain JavaScript and it opts out of all of typescript strong typing features an animal should always be an animal object but what if we Define it as a string will we get an error in this case we don't because an animal variable can be assigned to any data type so if we've introduced a bug in this code we wouldn't actually see it fail until runtime the same thing goes for function arguments say this function should always have a number and a string we could pass it other data types but it still won't fail until it reaches runtime now let's see how we can use typescript to prevent these bugs in the first place so we create an animal class that has these properties strong typed as a number and a string then when we declare the animal variable we can set it to this animal data type ensuring that it's always a JavaScript object with these exact properties when we Define the function we can set data types on the arguments to ensure that we can't accidentally pass the wrong data type to it and we can also Force this function to always return an instance of the animal class so we can't accidentally return the wrong value from a function so now let's try to use this code and see the difference in the feedback we get from the text editor if we call the function with the correct data types everything is all good there's no error but if we try to turn the number into a string we'll get instant feedback that this is the wrong data type so instead of waiting for this code to fail at runtime we know we've introduced a bug and know exactly how to fix it here another cool thing is we'll get feedback about the properties that exist on an object so if we try to call a certain function or property we know exactly what's there based on the feedback we get from typescript if we try to call a property that doesn't exist we'll get an error from typescript and our code won't compile in my opinion typescript is the single most important tool you have for debugging angular applications the next debugging tool look at is the debug statement from JavaScript a debugger statement will stop the execution of JavaScript which essentially allows you to pause your application at any point to inspect it in this example we have a component and we're going to add a debugger to the Constructor and also inside of an rxjs subscription now let's go to the app and see what happens when it hits that Constructor it pauses the app right here and brings up the file that we're trying to debug then we can hit the play button and it'll once again pause the application when it hits that subscription this can be very useful when you're not not sure exactly which component or service is causing the bug the next debugging tool we look at is the Json pipe this is something you can use to inspect data directly in the HTML it's especially useful when you're not sure exactly what an object looks like after retrieving it from a database or a third party API if we go into the app we can see that we're now seeing all the properties in this item listed in Json format now let's look at some of angular's built-in debugging tools to enable them we'll need to make some adjustments to the main.ts file after we bootstrap the app we'll have to enable debug tools on the app component itself check out the link in the description to just copy and paste this code the first thing we'll do is use NG probe which allows us to extract information from a component in the Dom so we do that by clicking on the component itself first in the HTML then we can use ng. probe dollar sign Z and that'll give us this debug element back which has a bunch of information about the component itself the other cool thing we can do is run a change detection profile which should happen very fast in this case it only takes 05 milliseconds per change detection cycle now let's take a look at the augury plugin for Chrome if you don't already have this installed go to the Chrome web store and get it installed today it's free and very powerful it gives you a visual picture of the app's components and services so you can easily debug things like sharing data between child and parent components as well as dependency injection with Services it also gives you a visual breakdown of your router so you can can see exactly which components are being imperatively loaded and lastly it gives you a breakdown of your NG modules this is a lot more efficient than looking up each file individually another strategy for debugging is to create your own custom logger this allows you to prioritize and customize the errors that you see in your app install it by running npm install angular 2- logger import it into the app module and it's a service so we'll add it to the providers list in that module then we can inject it into a component just like other service and start logging messages with various priorities in this case we'll do an error and a warn message then if we go into the console we can see we get these two different messages with different priorities and last but not least let's talk about debugging rxjs observables RX has a do operator that allows you to execute code within the observable chain without creating any side effects or impacting the underlying observable in this example we're retrieving an object observable from Firebase and then first we're going to just console L it then we're going to map it down to a string and then we'll console log it once again using the do operator so the do operator basically allows you to throw in any kind of debugging code you want within your observable as you're mapping or filtering it when we subscribe it will trigger the code inside these do operators in the app we can see we first get a console logged object and then we get that mapped down to an uppercase string afterwards that's it for angular debugging if this video helped you please like And subscribe and if you want to support the channel consider becoming a pro member at angular firebase.com you'll get a free copy of my book as well as one-on-one project Consulting designed to help you get your app shipped into production thanks for watching and I'll see you soon [Music]

Original Description

Learn seven effective strategies to debug Angular 4.x applications, including RxJS debugging methods. Checkout the full lesson code: https://angularfirebase.com/lessons/methods-for-debugging-an-angular-application/ Get the Augury plugin: https://chrome.google.com/webstore/detail/augury/elgalmkoelokbchhkhacckoklkejnhcd
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Fireship · Fireship · 36 of 60

1 Angular 4 Development and Production Environments with Firebase
Angular 4 Development and Production Environments with Firebase
Fireship
2 OAuth with Angular and Firebase Tutorial
OAuth with Angular and Firebase Tutorial
Fireship
3 Anonymous Authentication with Angular and Firebase - Lazy Registration
Anonymous Authentication with Angular and Firebase - Lazy Registration
Fireship
4 Angular Router Guards for Firebase Users
Angular Router Guards for Firebase Users
Fireship
5 Angular Firebase CRUD App with NoSQL Database Tutorial
Angular Firebase CRUD App with NoSQL Database Tutorial
Fireship
6 Upload Files from Angular to Firebase Storage
Upload Files from Angular to Firebase Storage
Fireship
7 How to Deploy an Angular App to Firebase Hosting
How to Deploy an Angular App to Firebase Hosting
Fireship
8 Sharing Data between Components in Angular
Sharing Data between Components in Angular
Fireship
9 Loading Spinners for Asynchronous Firebase Data
Loading Spinners for Asynchronous Firebase Data
Fireship
10 Angular 4 Transactional Email with Google Firebase Cloud Functions
Angular 4 Transactional Email with Google Firebase Cloud Functions
Fireship
11 Firebase Database Rules Tutorial
Firebase Database Rules Tutorial
Fireship
12 Autocomplete Search with Angular4 and Firebase
Autocomplete Search with Angular4 and Firebase
Fireship
13 Reddit Inspired Upvoting System with Angular and Firebase NoSQL
Reddit Inspired Upvoting System with Angular and Firebase NoSQL
Fireship
14 Angular Drag-and-Drop File Uploads to Firebase Storage
Angular Drag-and-Drop File Uploads to Firebase Storage
Fireship
15 Text Translation with Firebase Cloud Functions onWrite and Angular 4
Text Translation with Firebase Cloud Functions onWrite and Angular 4
Fireship
16 Custom Usernames with Firebase Authentication
Custom Usernames with Firebase Authentication
Fireship
17 Twitter-Inspired Follow Unfollow Feature with Firebase and Angular 4
Twitter-Inspired Follow Unfollow Feature with Firebase and Angular 4
Fireship
18 Simple Pagination with Firebase and Angular 4
Simple Pagination with Firebase and Angular 4
Fireship
19 How to Connect Firebase Users to their Data - 3 Methods
How to Connect Firebase Users to their Data - 3 Methods
Fireship
20 Add Toast Message Notifications to your Angular App
Add Toast Message Notifications to your Angular App
Fireship
21 Facebook-Inspired Reactions System with Angular and Firebase
Facebook-Inspired Reactions System with Angular and Firebase
Fireship
22 Learn NgModule in Angular with Examples
Learn NgModule in Angular with Examples
Fireship
23 Lazy Loading Components in Angular 4
Lazy Loading Components in Angular 4
Fireship
24 Stripe Checkout Payments with Angular and Firebase - Part 1
Stripe Checkout Payments with Angular and Firebase - Part 1
Fireship
25 Process Stripe Payments with Firebase Cloud Functions - Part 2
Process Stripe Payments with Firebase Cloud Functions - Part 2
Fireship
26 Selling Digital Content in Angular with Stripe Payments - Part 3
Selling Digital Content in Angular with Stripe Payments - Part 3
Fireship
27 Angular 4 Full Text Search with Algolia - Part 1
Angular 4 Full Text Search with Algolia - Part 1
Fireship
28 Algolia with Firebase Cloud Functions - Part 2
Algolia with Firebase Cloud Functions - Part 2
Fireship
29 Firebase Phone Authentication in Angular 4
Firebase Phone Authentication in Angular 4
Fireship
30 Top 7 RxJS Concepts for Angular Developers
Top 7 RxJS Concepts for Angular Developers
Fireship
31 Learn Angular Animations with 5 Examples
Learn Angular Animations with 5 Examples
Fireship
32 Advanced Firebase Data Filtering (Multi-Property)
Advanced Firebase Data Filtering (Multi-Property)
Fireship
33 Realtime Maps with Mapbox + Firebase + Angular
Realtime Maps with Mapbox + Firebase + Angular
Fireship
34 Angular Reactive Forms with Firebase Database Backend
Angular Reactive Forms with Firebase Database Backend
Fireship
35 Send Push Notifications in Angular with Firebase Cloud Messaging
Send Push Notifications in Angular with Firebase Cloud Messaging
Fireship
Top 7 Ways to Debug Angular 4 Apps
Top 7 Ways to Debug Angular 4 Apps
Fireship
37 Infinite Scroll with Angular and Firebase
Infinite Scroll with Angular and Firebase
Fireship
38 Use TypeScript with Firebase Cloud Functions
Use TypeScript with Firebase Cloud Functions
Fireship
39 Realtime Graphs and Charts with Plotly and Firebase
Realtime Graphs and Charts with Plotly and Firebase
Fireship
40 Role-Based User Permissions in Firebase
Role-Based User Permissions in Firebase
Fireship
41 User Presence System in Realtime - Online, Offline, Away
User Presence System in Realtime - Online, Offline, Away
Fireship
42 Location-based Queries with GeoFire and Angular Google Maps
Location-based Queries with GeoFire and Angular Google Maps
Fireship
43 Angular ngrx Redux Quick Start Tutorial
Angular ngrx Redux Quick Start Tutorial
Fireship
44 Angular Ngrx Effects with Firebase Database
Angular Ngrx Effects with Firebase Database
Fireship
45 Progressive Web Apps with Angular
Progressive Web Apps with Angular
Fireship
46 Angular Ngrx with Firebase Google OAuth User Authentication
Angular Ngrx with Firebase Google OAuth User Authentication
Fireship
47 RxJS Quick Start with Practical Examples
RxJS Quick Start with Practical Examples
Fireship
48 Send SMS Text Messages with Twilio and Firebase
Send SMS Text Messages with Twilio and Firebase
Fireship
49 Firebase Database Performance Profiling
Firebase Database Performance Profiling
Fireship
50 Native Desktop Apps with Angular and Electron
Native Desktop Apps with Angular and Electron
Fireship
51 Subscription Payments with Stripe, Angular, and Firebase
Subscription Payments with Stripe, Angular, and Firebase
Fireship
52 Firestore with AngularFire5 Quick Start Tutorial
Firestore with AngularFire5 Quick Start Tutorial
Fireship
53 Angular HTTP Client Quick Start Tutorial
Angular HTTP Client Quick Start Tutorial
Fireship
54 Google Sign-In with Firestore Custom User Data
Google Sign-In with Firestore Custom User Data
Fireship
55 Star Review System from Scratch with Firestore + Angular
Star Review System from Scratch with Firestore + Angular
Fireship
56 Angular Chatbot with Dialogflow (API.ai)
Angular Chatbot with Dialogflow (API.ai)
Fireship
57 Learn @ngrx/entity and Feature Modules
Learn @ngrx/entity and Feature Modules
Fireship
58 Infinite Scroll Pagination with Firestore
Infinite Scroll Pagination with Firestore
Fireship
59 Faster Firestore via Data Aggregation
Faster Firestore via Data Aggregation
Fireship
60 Contentful - CMS for Angular Progressive Web Apps
Contentful - CMS for Angular Progressive Web Apps
Fireship

This video teaches seven effective strategies for debugging Angular 4 applications, covering topics such as TypeScript, debugger statements, and RxJS debugging methods. By following these techniques, developers can efficiently identify and fix bugs in their Angular applications.

Key Takeaways
  1. Use TypeScript to write JavaScript code with static typing
  2. Add debugger statements to pause application execution
  3. Utilize JSON pipes to inspect data in HTML
  4. Enable Angular's built-in debugging tools
  5. Install and use the Augury plugin
  6. Create a custom logger for prioritized error messages
  7. Debug RxJS observables using the do operator
💡 TypeScript is a crucial tool for preventing bugs in Angular applications due to its static typing features.

Related Reads

📰
Claude Sonnet 5 Didn’t Just Get Smarter. It Changed the Economics of AI.
Learn how Claude Sonnet 5's advancements changed the economics of AI, making 'good enough AI' viable for production, and understand the implications for AI development and deployment
Medium · AI
📰
Claude Sonnet 5 Didn’t Just Get Smarter. It Changed the Economics of AI.
Claude Sonnet 5's improved AI capabilities have transformed the economics of AI, making it more viable for production
Medium · Machine Learning
📰
The AI Career Toolkit That Replaced My Job Hunt in 2026
Learn how to leverage AI tools to enhance your job search and career development in 2026
Dev.to · freelancewith_ai
📰
The AI Problem Nobody Saw Coming: The Decline Of Curiosity And Meaning
The rise of AI may lead to a decline in human curiosity, affecting innovation and our sense of meaning, and it's crucial to understand this potential consequence
Forbes Innovation
Up next
Man dies after horror Gold Coast house fire; high-speed Sydney motorway pursuit | 9 News Australia
9 News Australia
Watch →