Fireship · @fireship
Learn NgModule in Angular with Examples
Uploaded July 7, 2017 · Length 5:59
Summary
ngModule in Angular: organizing application structure with examples
- angular ngModule
- angular application structure
- module organization
- angular components
- angular services
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
in this episode we're going to talk
- 0:01
about ng module and how to properly use
- 0:04
it to organize an angular application so
- 0:07
what's the purpose of an ng module in
- 0:09
the first place the answer is it helps
- 0:12
organize the complex relationship
- 0:14
between views such as components and
- 0:16
directives to data providers such as
- 0:18
services and guards it works by allowing
- 0:21
you to define all these relationships in
- 0:23
the Swingle file as opposed to doing it
- 0:25
individually and every component service
- 0:28
as was the case in early days of angular
- 0:30
2 now let's look inside an NG module and
- 0:34
see what these metadata terms actually
- 0:36
mean first we have declarations which is
- 0:38
where you would put any component
- 0:40
directive or pipe and then it'll be
- 0:42
privately available to that module if
- 0:44
you want it to be publicly available to
- 0:46
other modules then you'll need to add it
- 0:49
to the export section this concept is
- 0:52
similar to public and private functions
- 0:54
and object-oriented programming
- 0:56
components will be private by default
- 0:58
and become public if you add them to
- 1:00
exports other modules gain access to
- 1:03
exported components by importing that
- 1:05
module in their own metadata
- 1:09
so just to recap declarations imports
- 1:12
and exports define the relationship
- 1:14
between components and how they're
- 1:16
shared between different ng modules next
- 1:20
we have the bootstrap property which
- 1:22
defines a component that's used to
- 1:24
initially load your application by
- 1:26
default this will usually be the app
- 1:28
component which is created automatically
- 1:30
by the angular CLI the final property
- 1:34
you should be aware of is providers this
- 1:37
is where you register data providers
- 1:38
such as Services and guards that can be
- 1:40
injected into components within this
- 1:42
module the injectable class will be
- 1:45
available to any component in this
- 1:47
module as well as any module that
- 1:49
imports it
- 1:50
now let's look at some practical ways we
- 1:53
can use energy module to organize an
- 1:55
application in this example we have all
- 1:58
of our components and services in the


