New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(aio): update architecture section #21569
Conversation
@StephenFluin - The old PR was hopelessly munged. Please review this new PR with the changes we discussed, and some of the restored content that was lost in the previous PR. |
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
You can preview a324941 at https://pr21569-a324941.ngbuilds.io/. |
You can preview d720ba1 at https://pr21569-d720ba1.ngbuilds.io/. |
@jbogarthyde, can you please squash all commits into one and rebase on master? |
d720ba1
to
fdc0d52
Compare
You can preview fdc0d52 at https://pr21569-fdc0d52.ngbuilds.io/. |
(wrong PR) |
Hi @jbogarthyde! This PR has merge conflicts due to recent upstream merges. |
1 similar comment
Hi @jbogarthyde! This PR has merge conflicts due to recent upstream merges. |
fdc0d52
to
4e9e77f
Compare
You can preview 4e9e77f at https://pr21569-4e9e77f.ngbuilds.io/. |
You can preview ffa43f0 at https://pr21569-ffa43f0.ngbuilds.io/. |
I don't think #21957 is fixed with this. |
You can preview 4ffe4bd at https://pr21569-4ffe4bd.ngbuilds.io/. |
This will also close issue #22158 |
5d7965b
to
7ccf9ac
Compare
You can preview 7ccf9ac at https://pr21569-7ccf9ac.ngbuilds.io/. |
7ccf9ac
to
784d54a
Compare
You can preview 784d54a at https://pr21569-784d54a.ngbuilds.io/. |
|
||
<code-example path="architecture/src/app/logger.service.ts" linenums="false" title="src/app/logger.service.ts (class)" region="class"></code-example> | ||
|
||
Here's a `HeroService` that uses a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) to fetch heroes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saying that it "uses a Promise to fetch" sounds weird.
It uses the Backend
service, which in turns uses something else under the hood (e.g. XMLHttpRequest
, fetch
, etc.) and returns a Promise to represent the future result/response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
<hr/> | ||
|
||
## Dependency injection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section makes it sound a little bit as if DI only works on components, while it also works (and is extensively used) in other places, such as services, pipes, NgModules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
* `imports`—Other modules whose exported classes are needed by component templates declared in _this_ NgModule. | ||
|
||
* `providers`—Creators of [services](guide/architecture-services) that this NgModule contributes to the global collection of services; they become accessible in all parts of the app. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they become accessible in all parts of the app
Not true for lazy-loaded modules, which get their own injector 😁
But maybe this simplification is fine for this introductory guide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added note that you can specify providers at component level (which is now preferred, since it makes them tree-shakeable).
|
||
<div class="l-sub-section"> | ||
|
||
The `export` of `AppComponent` is just to show how to export; it isn't actually necessary in this example. A root NgModule has no reason to _export_ anything because other components don't need to _import_ the root NgModule. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because other components --> because other modules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
## NgModules and components | ||
|
||
NgModules provide a _compilation context_ for their components. An NgModule has a root component, created during bootstrap, and any number of additional components that can be loaded (through the router) or created (through the template). The components that belong to an NgModule share a compilation context. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An NgModule has a root component, created during bootstrap
This mostly applies to the root NgModule only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work?
NgModules provide a compilation context for their components. A root NgModule always has a root component that is created during bootstrap, but any NgModule can include any number of additional components, which can be loaded through the router or created through the template. The components that belong to an NgModule share a compilation context.
|
||
* The `*ngFor` directive tells Angular to iterate over a list. | ||
* The `{{hero.name}}`, `(click)`, and `[hero]` bind program data to and from the DOM, responding to user input. See more about [data binding](#data-binding) below. | ||
* The `<app-hero-detail>` tag in the example is a custom element that represents a new component, `HeroDetailComponent`. The `HeroDetailComponent` (code not shown) is a child component of the `HeroListComponent` that defines the Hero-detail view. Notice how custom components like this mix seamlessly with native HTML in the same layouts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling a "custom element" is confusing (since people might think of https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
## Template syntax | ||
|
||
A template looks like regular HTML, except that it also contains Angular [template syntax](guide/template-syntax), which alters the HTML before the view is rendered, based on your app's logic and the state of app and DOM data. Your template can use _data binding_ to coordinate the app and DOM data, _pipes_ to transform data before it is displayed, and _directives_ to apply app logic to what gets displayed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which alters the HTML before the view is rendered
It can modify the HTML at any time, not just before the view is rendered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* The `[hero]` [*property binding*](guide/template-syntax#property-binding) passes the value of `selectedHero` from | ||
the parent `HeroListComponent` to the `hero` property of the child `HeroDetailComponent`. | ||
|
||
* The `(click)` [*event binding*](guide/user-input#click) calls the component's `selectHero` method when the user clicks a hero's name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not link to https://pr21569-784d54a.ngbuilds.io/guide/user-input#binding-to-user-input-events instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
* The `(click)` [*event binding*](guide/user-input#click) calls the component's `selectHero` method when the user clicks a hero's name. | ||
|
||
**Two-way data binding** is an important fourth form that combines property and event binding in a single notation, using the `ngModel` directive. Here's an example from the `HeroDetailComponent` template: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using the
ngModel
directive
This makes it sound as if two-way data binding is using (or depends on) ngModel
, which is not true. Two-way data binding has nothing to do with ngModel
, except for the fact that two-way data binding is often used to bind to ngModel
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
`{{interpolated_value | pipe_name}}` | ||
|
||
You can chain pipes, sending the output of one pipe function to be transformed by another pipe function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might also be worth mentioning (or showing in the example code-snippet above) that pipes can also take arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you provide an example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://angular.io/api/common/DatePipe#examples
(I.e. {{ interpolated_value | pipe_name : arg1 : arg2 }}
)
You can preview 96e6f45 at https://pr21569-96e6f45.ngbuilds.io/. |
96e6f45
to
ac2f558
Compare
You can preview ac2f558 at https://pr21569-ac2f558.ngbuilds.io/. |
You can preview 503647f at https://pr21569-503647f.ngbuilds.io/. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of minor comments.
Also the commits should be squashed together.
LGTM otherwise.
503647f
to
591b9a7
Compare
You can preview 591b9a7 at https://pr21569-591b9a7.ngbuilds.io/. |
Okay..finally passing all checks. Don't touch anything. :-) Merge merge quick. :-) |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Update doc with new section on architecture.