Fireship · @fireship

Top 7 Ways to Debug Angular 4 Apps

Uploaded August 5, 2017 · Length 6:28

Top 7 Ways to Debug Angular 4 Apps

Summary

7 techniques to debug angular 4 apps, including typescript, debugger statement, json pipe, ng probe, augury plugin, custom logger, and rxjs do operator.

  • angular debugging
  • typescript debugging
  • angular 4 debugging
  • javascript debugging
  • rxjs debugging
  • angular tools
  • debugging angular apps

Transcript preview

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

  1. 0:00

    debugging is easily one of the most

  2. 0:01

    annoying and frustrating aspects of a

  3. 0:03

    programmer's life in this episode I'm

  4. 0:05

    going to cover seven different

  5. 0:07

    techniques that you can use to debug

  6. 0:09

    angular 4 applications hopefully this

  7. 0:11

    will save you some time and frustration

  8. 0:12

    as you build your

  9. 0:13

    app the great thing about angular is

  10. 0:16

    that it uses typescript by default which

  11. 0:18

    prevents many of the bugs that plague

  12. 0:20

    JavaScript applications it does this by

  13. 0:22

    allowing you to write JavaScript code

  14. 0:24

    with static typing as opposed to Dynamic

  15. 0:26

    typing this just means you define the

  16. 0:28

    data types and properties of object

  17. 0:30

    before they're actually used in the code

  18. 0:32

    so why is this beneficial well the

  19. 0:34

    number one reason is it allows your text

  20. 0:36

    editor to give you instant feedback

  21. 0:38

    whenever you're about to introduce a bug

  22. 0:40

    into your code take a look at this code

  23. 0:42

    here it's more or less just plain

  24. 0:43

    JavaScript and it opts out of all of

  25. 0:45

    typescript strong typing features an

  26. 0:48

    animal should always be an animal object

  27. 0:50

    but what if we Define it as a string

  28. 0:52

    will we get an error in this case we

  29. 0:54

    don't because an animal variable can be

  30. 0:56

    assigned to any data type so if we've

  31. 0:58

    introduced a bug in this code we

  32. 1:00

    wouldn't actually see it fail until

  33. 1:01

    runtime the same thing goes for function

  34. 1:04

    arguments say this function should

  35. 1:05

    always have a number and a string we

  36. 1:07

    could pass it other data types but it

  37. 1:09

    still won't fail until it reaches

  38. 1:11

    runtime now let's see how we can use

  39. 1:13

    typescript to prevent these bugs in the

  40. 1:15

    first place so we create an animal class

  41. 1:17

    that has these properties strong typed

  42. 1:19

    as a number and a string then when we

  43. 1:21

    declare the animal variable we can set

  44. 1:24

    it to this animal data type ensuring

  45. 1:25

    that it's always a JavaScript object

  46. 1:27

    with these exact properties when we

  47. 1:29

    Define the function we can set data

  48. 1:31

    types on the arguments to ensure that we

  49. 1:33

    can't accidentally pass the wrong data

  50. 1:34

    type to it and we can also Force this

  51. 1:37

    function to always return an instance of

  52. 1:39

    the animal class so we can't

  53. 1:41

    accidentally return the wrong value from

  54. 1:43

    a function so now let's try to use this

  55. 1:45

    code and see the difference in the

  56. 1:47

    feedback we get from the text

  57. 1:49

    editor if we call the function with the

  58. 1:51

    correct data types everything is all

  59. 1:53

    good there's no error but if we try to

  60. 1:55

    turn the number into a string we'll get

  61. 1:57

    instant feedback that this is the wrong

  62. 1:58

    data type so instead of waiting for this