Fireship · @fireship
Top 7 Ways to Debug Angular 4 Apps
Uploaded August 5, 2017 · Length 6:28
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.
- 0:00
debugging is easily one of the most
- 0:01
annoying and frustrating aspects of a
- 0:03
programmer's life in this episode I'm
- 0:05
going to cover seven different
- 0:07
techniques that you can use to debug
- 0:09
angular 4 applications hopefully this
- 0:11
will save you some time and frustration
- 0:12
as you build your
- 0:13
app the great thing about angular is
- 0:16
that it uses typescript by default which
- 0:18
prevents many of the bugs that plague
- 0:20
JavaScript applications it does this by
- 0:22
allowing you to write JavaScript code
- 0:24
with static typing as opposed to Dynamic
- 0:26
typing this just means you define the
- 0:28
data types and properties of object
- 0:30
before they're actually used in the code
- 0:32
so why is this beneficial well the
- 0:34
number one reason is it allows your text
- 0:36
editor to give you instant feedback
- 0:38
whenever you're about to introduce a bug
- 0:40
into your code take a look at this code
- 0:42
here it's more or less just plain
- 0:43
JavaScript and it opts out of all of
- 0:45
typescript strong typing features an
- 0:48
animal should always be an animal object
- 0:50
but what if we Define it as a string
- 0:52
will we get an error in this case we
- 0:54
don't because an animal variable can be
- 0:56
assigned to any data type so if we've
- 0:58
introduced a bug in this code we
- 1:00
wouldn't actually see it fail until
- 1:01
runtime the same thing goes for function
- 1:04
arguments say this function should
- 1:05
always have a number and a string we
- 1:07
could pass it other data types but it
- 1:09
still won't fail until it reaches
- 1:11
runtime now let's see how we can use
- 1:13
typescript to prevent these bugs in the
- 1:15
first place so we create an animal class
- 1:17
that has these properties strong typed
- 1:19
as a number and a string then when we
- 1:21
declare the animal variable we can set
- 1:24
it to this animal data type ensuring
- 1:25
that it's always a JavaScript object
- 1:27
with these exact properties when we
- 1:29
Define the function we can set data
- 1:31
types on the arguments to ensure that we
- 1:33
can't accidentally pass the wrong data
- 1:34
type to it and we can also Force this
- 1:37
function to always return an instance of
- 1:39
the animal class so we can't
- 1:41
accidentally return the wrong value from
- 1:43
a function so now let's try to use this
- 1:45
code and see the difference in the
- 1:47
feedback we get from the text
- 1:49
editor if we call the function with the
- 1:51
correct data types everything is all
- 1:53
good there's no error but if we try to
- 1:55
turn the number into a string we'll get
- 1:57
instant feedback that this is the wrong
- 1:58
data type so instead of waiting for this


