Skip to content

Commit ab4b22e

Browse files
wardbellFoxandxss
authored andcommitted
docs: Bootstrapping guide prose for CLI
1 parent 3db7112 commit ab4b22e

File tree

1 file changed

+70
-82
lines changed

1 file changed

+70
-82
lines changed

aio/content/guide/bootstrapping.md

+70-82
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,83 @@
11
# Bootstrapping
22

3-
An NgModule class describes how the application parts fit together.
4-
Every application has at least one NgModule, the _root_ module
3+
An Angular Module (NgModule) class describes how the application parts fit together.
4+
Every application has at least one Angular Module, the _root_ module
55
that you [bootstrap](#main) to launch the application.
6-
You can call it anything you want. The conventional name is `AppModule`.
6+
You can call the class anything you want. The conventional name is `AppModule`.
77

8-
The [setup](guide/setup) instructions produce a new project with the following minimal `AppModule`.
9-
You'll evolve this module as your application grows.
8+
The [**Angular CLI**](https://cli.angular.io/) produces a new project with the following minimal `AppModule`.
9+
You evolve this module as your application grows.
1010

11-
12-
<code-example path="setup/src/app/app.module.ts" title="src/app/app.module.ts" linenums="false">
11+
<code-example path="cli-quickstart/src/app/app.module.ts" title="src/app/app.module.ts" linenums="false">
1312
</code-example>
1413

1514

16-
1715
After the `import` statements, you come to a class adorned with the
1816
**`@NgModule`** [_decorator_](guide/glossary#decorator '"Decorator" explained').
1917

2018
The `@NgModule` decorator identifies `AppModule` as an `NgModule` class.
2119
`@NgModule` takes a _metadata_ object that tells Angular how to compile and launch the application.
2220

23-
* **_imports_** &mdash; the `BrowserModule` that this and every application needs to run in a browser.
24-
* **_declarations_** &mdash; the application's lone component, which is also ...
25-
* **_bootstrap_** &mdash; the _root_ component that Angular creates and inserts into the `index.html` host web page.
21+
The `@NgModule` properties for the minimal `AppModule` generated by the CLI are as follows:
2622

27-
The [NgModules](guide/ngmodule) guide dives deeply into the details of NgModules.
28-
All you need to know at the moment is a few basics about these three properties.
23+
* **[_declarations_](#declarations)** &mdash; declares the application components. At the moment, there is only the `AppComponent`.
2924

3025

31-
{@a imports}
26+
* **[_imports_](#imports)** &mdash; the `BrowserModule`, which this and every application must import in order to run the app in a browser.
3227

3328

34-
### The _imports_ array
29+
* **[_providers_](#providers)** &mdash; there are none to start but you are likely to add some soon.
3530

36-
NgModules are a way to consolidate features that belong together into discrete units.
37-
Many features of Angular itself are organized as NgModules.
38-
HTTP services are in the `HttpModule`. The router is in the `RouterModule`.
39-
Eventually you may create a feature module.
4031

41-
Add a module to the `imports` array when the application requires its features.
32+
* **[_bootstrap_](#bootstrap-array)** &mdash; the _root_ `AppComponent` that Angular creates and inserts into the `index.html` host web page.
4233

43-
_This_ application, like most applications, executes in a browser.
44-
Every application that executes in a browser needs the `BrowserModule` from `@angular/platform-browser`.
45-
So every such application includes the `BrowserModule` in its _root_ `AppModule`'s `imports` array.
46-
Other guide and cookbook pages will tell you when you need to add additional modules to this array.
34+
The [Angular Modules (NgModules)](guide/ngmodule) guide dives deeply into the details of `@NgModule`.
35+
All you need to know at the moment is a few basics about these four properties.
36+
37+
{@a declarations}
4738

4839

49-
<div class="alert is-important">
40+
### The _declarations_ array
5041

42+
You tell Angular which components belong to the `AppModule` by listing it in the module's `declarations` array.
43+
As you create more components, you'll add them to `declarations`.
5144

45+
You must declare _every_ component in an Angular Module class.
46+
If you use a component without declaring it, you'll see a clear error message in the browser console.
47+
48+
You'll learn to create two other kinds of classes &mdash;
49+
[directives](guide/attribute-directives) and [pipes](guide/pipes) &mdash;
50+
that you must also add to the `declarations` array.
5251

53-
**Only `NgModule` classes** go in the `imports` array. Do not put any other kind of class in `imports`.
52+
<div class="alert is-important">
5453

54+
**Only _declarables_** &mdash; _components_, _directives_ and _pipes_ &mdash; belong in the `declarations` array.
55+
Do not put any other kind of class in `declarations`. Do _not_ declare `NgModule` classes. Do _not_ declare service classes. Do _not_ declare model classes.
5556

5657
</div>
5758

59+
{@a imports}
5860

61+
### The _imports_ array
5962

60-
<div class="l-sub-section">
63+
Angular Modules are a way to consolidate features that belong together into discrete units.
64+
Many features of Angular itself are organized as Angular Modules.
65+
HTTP services are in the `HttpClientModule`. The router is in the `RouterModule`.
66+
Eventually you may create your own modules.
67+
68+
Add a module to the `imports` array when the application requires its features.
69+
70+
_This_ application, like most applications, executes in a browser.
71+
Every application that executes in a browser needs the `BrowserModule` from `@angular/platform-browser`.
72+
So every such application includes the `BrowserModule` in its _root_ `AppModule`'s `imports` array.
73+
Other guide pages will tell you when you need to add additional modules to this array.
6174

75+
<div class="alert is-important">
6276

77+
**Only `@NgModule` classes** go in the `imports` array. Do not put any other kind of class in `imports`.
78+
</div>
79+
80+
<div class="l-sub-section">
6381

6482
The `import` statements at the top of the file and the NgModule's `imports` array
6583
are unrelated and have completely different jobs.
@@ -70,44 +88,30 @@ You add `import` statements to almost every application file.
7088
They have nothing to do with Angular and Angular knows nothing about them.
7189

7290
The _module's_ `imports` array appears _exclusively_ in the `@NgModule` metadata object.
73-
It tells Angular about specific _other_ NgModules&mdash;all of them classes decorated
91+
It tells Angular about specific _other_ Angular Modules&mdash;all of them classes decorated
7492
with `@NgModule`&mdash;that the application needs to function properly.
7593

7694
</div>
7795

96+
{@a providers}
7897

98+
### The _providers_ array
7999

80-
{@a declarations}
100+
Angular apps rely on [_dependency injection (DI)_](guide/dependency-injection)
101+
to deliver services to various parts of the application.
81102

103+
Before DI can inject a service, it must create that service with the help of a _provider_.
104+
You can tell DI about a service's _provider_ in a number of ways.
105+
Among the most popular ways is to register the service in the root `ngModule.providers` array, which will make that service available _everywhere_.
82106

83-
### The _declarations_ array
84-
85-
You tell Angular which components belong to the `AppModule` by listing it in the module's `declarations` array.
86-
As you create more components, you'll add them to `declarations`.
87-
88-
You must declare _every_ component in an `NgModule` class.
89-
If you use a component without declaring it, you'll see a clear error message in the browser console.
90-
91-
You'll learn to create two other kinds of classes &mdash;
92-
[directives](guide/attribute-directives) and [pipes](guide/pipes) &mdash;
93-
that you must also add to the `declarations` array.
94-
95-
96-
<div class="alert is-important">
97-
98-
99-
100-
**Only _declarables_** &mdash; _components_, _directives_ and _pipes_ &mdash; belong in the `declarations` array.
101-
Do not put any other kind of class in `declarations`; _not_ `NgModule` classes, _not_ service classes, _not_ model classes.
102-
103-
104-
</div>
105-
107+
For example, a data service provided in the `AppModule`s _providers_ can be injected into any
108+
component anywhere in the application.
106109

110+
You don't have any services to provide yet.
111+
But you will create some before long and you may chose to provide many of them here.
107112

108113
{@a bootstrap-array}
109114

110-
111115
### The _bootstrap_ array
112116

113117
You launch the application by [_bootstrapping_](#main) the root `AppModule`.
@@ -124,58 +128,42 @@ You can call the one _root_ component anything you want but most developers call
124128

125129
Which brings us to the _bootstrapping_ process itself.
126130

127-
128131
{@a main}
129132

130133
## Bootstrap in _main.ts_
131134

132-
There are many ways to bootstrap an application.
133-
The variations depend upon how you want to compile the application and where you want to run it.
134-
135-
In the beginning, you will compile the application dynamically with the _Just-in-Time (JIT)_ compiler
136-
and you'll run it in a browser. You can learn about other options later.
137-
138-
The recommended place to bootstrap a JIT-compiled browser application is in a separate file
139-
in the `src` folder named `src/main.ts`
140-
141-
<code-example path="setup/src/main.ts" title="src/main.ts" linenums="false">
135+
While there are many ways to bootstrap an application, most applications do so in the `src/main.ts` that is generated by the Angular CLI.
142136

137+
<code-example path="cli-quickstart/src/main.ts" title="src/main.ts" linenums="false">
143138
</code-example>
144139

145-
146-
147-
This code creates a browser platform for dynamic (JIT) compilation and
140+
This code creates a browser platform for dynamic compilation and
148141
bootstraps the `AppModule` described above.
149142

150143
The _bootstrapping_ process sets up the execution environment,
151144
digs the _root_ `AppComponent` out of the module's `bootstrap` array,
152145
creates an instance of the component and inserts it within the element tag identified by the component's `selector`.
153146

154-
The `AppComponent` selector &mdash; here and in most documentation samples &mdash; is `my-app`
155-
so Angular looks for a `<my-app>` tag in the `index.html` like this one ...
147+
The `AppComponent` selector &mdash; here and in most documentation samples &mdash; is `app-root`
148+
so Angular looks for a `<app-root>` tag in the `index.html` like this one ...
156149

157-
<code-example path="setup/src/index.html" region="my-app" title="setup/src/index.html" linenums="false">
158-
159-
</code-example>
150+
<code-example title="src/index.html (body)" linenums="false">
160151

152+
&lt;body>
153+
&lt;app-root>&lt;/app-root>
154+
&lt;/body>
161155

156+
</code-example>
162157

163158
... and displays the `AppComponent` there.
164159

165-
This file is very stable. Once you've set it up, you may never change it again.
166-
167-
168-
<l-main-section>
169-
170-
</l-main-section>
171-
172-
160+
The `main.ts` file is very stable. Once you've set it up, you may never change it again.
173161

174-
## More about NgModules
162+
## More about Angular Modules
175163

176164
Your initial app has only a single module, the _root_ module.
177165
As your app grows, you'll consider subdividing it into multiple "feature" modules,
178166
some of which can be loaded later ("lazy loaded") if and when the user chooses
179167
to visit those features.
180168

181-
When you're ready to explore these possibilities, visit the [NgModules](guide/ngmodule) guide.
169+
When you're ready to explore these possibilities, visit the [Angular Modules](guide/ngmodule) guide.

0 commit comments

Comments
 (0)