Compare commits
200 Commits
10.0.0-rc.
...
10.0.4
Author | SHA1 | Date | |
---|---|---|---|
13d176302b | |||
e3b801053a | |||
6626739798 | |||
396033da80 | |||
02ee9d2938 | |||
a4c7f183d7 | |||
d690eec88f | |||
10e4dfae27 | |||
f8d948b46b | |||
9cf78d5701 | |||
45471dbbd6 | |||
387e8386d1 | |||
eec6e4be7a | |||
b711f25892 | |||
788f0453f7 | |||
45b1775a53 | |||
53e4ff72d2 | |||
7813a7d129 | |||
c0ced6dc2d | |||
8157ee87b0 | |||
ab051aba27 | |||
5a61ef0c49 | |||
c451dbda9f | |||
0d38288078 | |||
2e9b953e9d | |||
a94383f168 | |||
75c40ddd61 | |||
86a75a0670 | |||
c776825fdd | |||
1cc9383d91 | |||
8ed1e53e99 | |||
7833c88ac4 | |||
12f177399f | |||
5be32366be | |||
5b7d2eeabf | |||
6cd10a1b10 | |||
822652aa0d | |||
cf47ace493 | |||
0595f11950 | |||
35df312ea4 | |||
489eb8519e | |||
b76a2dc2cb | |||
f2f5f7fc6e | |||
8ee23ba67b | |||
ecb422b360 | |||
60389d5441 | |||
b186db70db | |||
324b6f1b1a | |||
cdba1d37a4 | |||
dc42c97ee4 | |||
bc00e8d312 | |||
720b71d01f | |||
1132b07c53 | |||
9230194794 | |||
d724896f04 | |||
29866dfb91 | |||
a249622159 | |||
9f2393fb80 | |||
d5f8040d0a | |||
e0b8ea136b | |||
879b2273c1 | |||
f24972b1b1 | |||
d2886b3bb4 | |||
f296fea112 | |||
2605fc46e7 | |||
9d54b3a14b | |||
d09a6283ed | |||
1c168c3a44 | |||
0f74479c47 | |||
790bb949f6 | |||
2adcad6dd2 | |||
242ef1ace1 | |||
842b6a1247 | |||
98335529eb | |||
ca7ee794bf | |||
f9f2ba6faf | |||
aea1d211d4 | |||
57a518a36d | |||
29b83189b0 | |||
1d3df7885d | |||
fd06ffa2af | |||
36a1622dd1 | |||
7a91b23cb5 | |||
4b90b6a226 | |||
b13daa4cdf | |||
0c6f026828 | |||
a2520bd267 | |||
b928a209a4 | |||
89e16ed6a5 | |||
1a1f99af37 | |||
df2cd37ed2 | |||
12a71bc6bc | |||
7d270c235a | |||
b0b7248504 | |||
78460c1848 | |||
75b119eafc | |||
64b0ae93f7 | |||
7c0b25f5a6 | |||
07b5df3a19 | |||
e7023726f4 | |||
a9ccd9254c | |||
335f3271d2 | |||
7f93f7ef47 | |||
cf46a87fcd | |||
ad6680f602 | |||
5e287f67af | |||
ecfe6e0609 | |||
df9790dd11 | |||
67cfc4c9bc | |||
a68e623c80 | |||
9e3915ba48 | |||
ba2de61748 | |||
a9a4edebe2 | |||
64f2ffa166 | |||
13020b9cc2 | |||
96b96fba0f | |||
2cbe53a9ba | |||
48755114e5 | |||
a5d5f67be7 | |||
dfb58c44a2 | |||
69948ce919 | |||
3190ccf3b2 | |||
a8ea8173aa | |||
e13a49d1f0 | |||
2f0b8f675a | |||
c2aed033ba | |||
0f8a780b0d | |||
c5bc2e77c8 | |||
079310dc7c | |||
0d2cdf6165 | |||
436dde271f | |||
96891a076f | |||
9ce0067bdf | |||
345940bbc1 | |||
c49507b289 | |||
c730142508 | |||
27aa00b15f | |||
36a00a255b | |||
0e3249c89b | |||
920019ab70 | |||
82c8b44db7 | |||
bb3a307d5a | |||
dcb0ddaf5e | |||
4c1edd52c5 | |||
d512e27979 | |||
0619d82e0b | |||
a4038d5b94 | |||
e3d5e1fab7 | |||
035036308a | |||
0d29259d9b | |||
26b0f3dc96 | |||
5c9306b0fe | |||
3befb0e4b9 | |||
97bb88f10b | |||
6c7467a58b | |||
c579a85c12 | |||
400fdd08fd | |||
c1fe6c9c81 | |||
c58a0bea91 | |||
88a934b93c | |||
cde5cced69 | |||
472bedd3ea | |||
d8a06d03bd | |||
32020f9fb3 | |||
d574b14934 | |||
00c5d89e7d | |||
d2c8aefe64 | |||
ba796bbdd3 | |||
a0bb2ba7b7 | |||
f9fa3b5b6c | |||
f89d438116 | |||
1abe791d46 | |||
1502ae78b6 | |||
bad6e719de | |||
8c7129f3d2 | |||
dbff6f71e1 | |||
fcd934ccf6 | |||
45a8f340d9 | |||
5856513405 | |||
01fa3ee5c3 | |||
b8d69ffdf3 | |||
7ef60ec2a9 | |||
83f905c0e1 | |||
72ba3a3918 | |||
df10597da4 | |||
5db2e794a9 | |||
486aa06747 | |||
01ce1b32df | |||
c78b0b2c51 | |||
9ade1c3ea3 | |||
315a4cfcd4 | |||
11c04027ab | |||
eabe3b4c39 | |||
d471454675 | |||
bf57776b59 | |||
a32579ae5b | |||
780601d27a | |||
c909e731d7 | |||
9b8eb42354 | |||
0757174e8e |
@ -19,4 +19,12 @@ build --local_ram_resources=14336
|
|||||||
|
|
||||||
# All build executed remotely should be done using our RBE configuration.
|
# All build executed remotely should be done using our RBE configuration.
|
||||||
build:remote --google_default_credentials
|
build:remote --google_default_credentials
|
||||||
|
|
||||||
|
# Upload to GCP's Build Status viewer to allow for us to have better viewing of execution/build
|
||||||
|
# logs. This is only done on CI as the BES (GCP's Build Status viewer) API requires credentials
|
||||||
|
# from service accounts, rather than end user accounts.
|
||||||
|
build:remote --bes_backend=buildeventservice.googleapis.com
|
||||||
|
build:remote --bes_timeout=30s
|
||||||
|
build:remote --bes_results_url="https://source.cloud.google.com/results/invocations/"
|
||||||
|
|
||||||
build --config=remote
|
build --config=remote
|
||||||
|
@ -32,7 +32,7 @@ var_4_win: &cache_key_win_fallback v7-angular-win-node-12-{{ checksum ".bazelver
|
|||||||
|
|
||||||
# Cache key for the `components-repo-unit-tests` job. **Note** when updating the SHA in the
|
# Cache key for the `components-repo-unit-tests` job. **Note** when updating the SHA in the
|
||||||
# cache keys also update the SHA for the "COMPONENTS_REPO_COMMIT" environment variable.
|
# cache keys also update the SHA for the "COMPONENTS_REPO_COMMIT" environment variable.
|
||||||
var_5: &components_repo_unit_tests_cache_key v7-angular-components-189d98e8b01b33974328255f085de04251d61567
|
var_5: &components_repo_unit_tests_cache_key v7-angular-components-f428c00465dfcf8a020237f22532480eedbd2cb6
|
||||||
var_6: &components_repo_unit_tests_cache_key_fallback v7-angular-components-
|
var_6: &components_repo_unit_tests_cache_key_fallback v7-angular-components-
|
||||||
|
|
||||||
# Workspace initially persisted by the `setup` job, and then enhanced by `build-npm-packages` and
|
# Workspace initially persisted by the `setup` job, and then enhanced by `build-npm-packages` and
|
||||||
|
@ -74,7 +74,7 @@ setPublicVar COMPONENTS_REPO_TMP_DIR "/tmp/angular-components-repo"
|
|||||||
setPublicVar COMPONENTS_REPO_URL "https://github.com/angular/components.git"
|
setPublicVar COMPONENTS_REPO_URL "https://github.com/angular/components.git"
|
||||||
setPublicVar COMPONENTS_REPO_BRANCH "master"
|
setPublicVar COMPONENTS_REPO_BRANCH "master"
|
||||||
# **NOTE**: When updating the commit SHA, also update the cache key in the CircleCI `config.yml`.
|
# **NOTE**: When updating the commit SHA, also update the cache key in the CircleCI `config.yml`.
|
||||||
setPublicVar COMPONENTS_REPO_COMMIT "189d98e8b01b33974328255f085de04251d61567"
|
setPublicVar COMPONENTS_REPO_COMMIT "f428c00465dfcf8a020237f22532480eedbd2cb6"
|
||||||
|
|
||||||
|
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
|
@ -60,14 +60,15 @@ if (require.resolve === module) {
|
|||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
function _main(args) {
|
function _main(args) {
|
||||||
triggerWebhook(...args).
|
triggerWebhook(...args)
|
||||||
then(({statusCode, responseText}) => (200 <= statusCode && statusCode < 400) ?
|
.then(
|
||||||
console.log(`Status: ${statusCode}\n${responseText}`) :
|
({statusCode, responseText}) => (200 <= statusCode && statusCode < 400) ?
|
||||||
Promise.reject(new Error(`Request failed (status: ${statusCode}): ${responseText}`))).
|
console.log(`Status: ${statusCode}\n${responseText}`) :
|
||||||
catch(err => {
|
Promise.reject(new Error(`Request failed (status: ${statusCode}): ${responseText}`)))
|
||||||
console.error(err);
|
.catch(err => {
|
||||||
process.exit(1);
|
console.error(err);
|
||||||
});
|
process.exit(1);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function postJson(url, data) {
|
function postJson(url, data) {
|
||||||
@ -77,15 +78,12 @@ function postJson(url, data) {
|
|||||||
const statusCode = res.statusCode || -1;
|
const statusCode = res.statusCode || -1;
|
||||||
let responseText = '';
|
let responseText = '';
|
||||||
|
|
||||||
res.
|
res.on('error', reject)
|
||||||
on('error', reject).
|
.on('data', d => responseText += d)
|
||||||
on('data', d => responseText += d).
|
.on('end', () => resolve({statusCode, responseText}));
|
||||||
on('end', () => resolve({statusCode, responseText}));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
request(url, opts, onResponse).
|
request(url, opts, onResponse).on('error', reject).end(JSON.stringify(data));
|
||||||
on('error', reject).
|
|
||||||
end(JSON.stringify(data));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
145
.gitmessage
Normal file
145
.gitmessage
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
<type>(<scope>): <summary>
|
||||||
|
|
||||||
|
<Describe the motivation behind this change - explain WHY you are making this change. Wrap all lines
|
||||||
|
at 100 characters.>
|
||||||
|
|
||||||
|
Fixes #<issue number>
|
||||||
|
|
||||||
|
# ────────────────────────────────────────── 100 chars ────────────────────────────────────────────┤
|
||||||
|
|
||||||
|
|
||||||
|
# Example Commit Messages
|
||||||
|
# =======================
|
||||||
|
|
||||||
|
|
||||||
|
# ─── Example: Simple refactor ────────────────────────────────────────────────────────────────────┤
|
||||||
|
# refactor(core): rename refreshDynamicEmbeddedViews to refreshEmbeddedViews
|
||||||
|
#
|
||||||
|
# Improve code readability. The original name no longer matches how the function is used.
|
||||||
|
# ─────────────────────────────────────────────────────────────────────────────────────────────────┤
|
||||||
|
|
||||||
|
|
||||||
|
# ─── Example: Simple docs change ─────────────────────────────────────────────────────────────────┤
|
||||||
|
# docs: clarify the service limitation in providers.md guide
|
||||||
|
#
|
||||||
|
# Fixes #36332
|
||||||
|
# ─────────────────────────────────────────────────────────────────────────────────────────────────┤
|
||||||
|
|
||||||
|
|
||||||
|
# ─── Example: A bug fix ──────────────────────────────────────────────────────────────────────────┤
|
||||||
|
# fix(ngcc): ensure lockfile is removed when `analyzeFn` fails
|
||||||
|
#
|
||||||
|
# Previously an error thrown in the `analyzeFn` would cause the ngcc process to exit immediately
|
||||||
|
# without removing the lockfile, and potentially before the unlocker process had been successfully
|
||||||
|
# spawned resulting in the lockfile being orphaned and left behind.
|
||||||
|
#
|
||||||
|
# Now we catch these errors and remove the lockfile as needed.
|
||||||
|
# ─────────────────────────────────────────────────────────────────────────────────────────────────┤
|
||||||
|
|
||||||
|
|
||||||
|
# ─── Example: Breaking change ────────────────────────────────────────────────────────────────────┤
|
||||||
|
# feat(bazel): simplify ng_package by dropping esm5 and fesm5
|
||||||
|
#
|
||||||
|
# esm5 and fesm5 distributions are no longer needed and have been deprecated in the past.
|
||||||
|
#
|
||||||
|
# https://v9.angular.io/guide/deprecations#esm5-and-fesm5-code-formats-in-angular-npm-packages
|
||||||
|
#
|
||||||
|
# This commit modifies ng_package to no longer distribute these two formats in npm packages built by
|
||||||
|
# ng_package (e.g. @angular/core).
|
||||||
|
#
|
||||||
|
# This commit intentionally doesn't fully clean up the ng_package rule to remove all traces of esm5
|
||||||
|
# and fems5 build artifacts as that is a bigger cleanup and currently we are narrowing down the
|
||||||
|
# scope of this change to the MVP needed for v10, which in this case is 'do not put esm5 and fesm5'
|
||||||
|
# into the npm packages.
|
||||||
|
#
|
||||||
|
# More cleanup to follow: https://angular-team.atlassian.net/browse/FW-2143
|
||||||
|
#
|
||||||
|
# BREAKING CHANGE: esm5 and fesm5 format is no longer distributed in Angular's npm packages e.g.
|
||||||
|
# @angular/core
|
||||||
|
#
|
||||||
|
# Angular CLI will automatically downlevel the code to es5 if differential loading is enabled in the
|
||||||
|
# Angular project, so no action is required from Angular CLI users.
|
||||||
|
#
|
||||||
|
# If you are not using Angular CLI to build your application or library, and you need to be able to
|
||||||
|
# build es5 artifacts, then you will need to downlevel the distributed Angular code to es5 on your
|
||||||
|
# own.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Fixes #1234
|
||||||
|
# ─────────────────────────────────────────────────────────────────────────────────────────────────┤
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Angular Commit Message Format
|
||||||
|
# =============================
|
||||||
|
#
|
||||||
|
# The full specification of the Angular Commit Message Format can be found at
|
||||||
|
# https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit
|
||||||
|
#
|
||||||
|
# The following is an excerpt of the specification with the most commonly needed info.
|
||||||
|
#
|
||||||
|
# Each commit message consists of a *header*, a *body*, and a *footer*.
|
||||||
|
#
|
||||||
|
# <header>
|
||||||
|
# <BLANK LINE>
|
||||||
|
# <body>
|
||||||
|
# <BLANK LINE>
|
||||||
|
# <footer>
|
||||||
|
#
|
||||||
|
# The header is mandatory.
|
||||||
|
#
|
||||||
|
# The body is mandatory for all commits except for those of scope "docs". When the body is required
|
||||||
|
# it must be at least 20 characters long.
|
||||||
|
#
|
||||||
|
# The footer is optional.
|
||||||
|
#
|
||||||
|
# Any line of the commit message cannot be longer than 100 characters.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Commit Message Header
|
||||||
|
# ---------------------
|
||||||
|
#
|
||||||
|
# <type>(<scope>): <short summary>
|
||||||
|
# │ │ │
|
||||||
|
# │ │ └─⫸ Summary in present tense. Not capitalized. No period at the end.
|
||||||
|
# │ │
|
||||||
|
# │ └─⫸ Commit Scope: animations|bazel|benchpress|common|compiler|compiler-cli|core|
|
||||||
|
# │ elements|forms|http|language-service|localize|platform-browser|
|
||||||
|
# │ platform-browser-dynamic|platform-server|platform-webworker|
|
||||||
|
# │ platform-webworker-dynamic|router|service-worker|upgrade|zone.js|
|
||||||
|
# │ packaging|changelog|dev-infra|docs-infra|migrations|ngcc|ve
|
||||||
|
# │ https://github.com/angular/angular/blob/master/CONTRIBUTING.md#scope
|
||||||
|
# │
|
||||||
|
# └─⫸ Commit Type: build|ci|docs|feat|fix|perf|refactor|style|test
|
||||||
|
# https://github.com/angular/angular/blob/master/CONTRIBUTING.md#type
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Commit Message Body
|
||||||
|
# ---------------------
|
||||||
|
#
|
||||||
|
# Just as in the summary, use the imperative, present tense: "fix" not "fixed" nor "fixes".
|
||||||
|
#
|
||||||
|
# Explain the motivation for the change in the commit message body. This commit message should
|
||||||
|
# explain WHY you are making the change. You can include a comparison of the previous behavior with
|
||||||
|
# the new behavior in order to illustrate the impact of the change.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Commit Message Footer
|
||||||
|
# ---------------------
|
||||||
|
#
|
||||||
|
# The footer can contain information about breaking changes and is also the place to reference
|
||||||
|
# GitHub issues, Jira tickets, and other PRs that this commit closes or is related to.
|
||||||
|
#
|
||||||
|
# ```
|
||||||
|
# BREAKING CHANGE: <breaking change summary>
|
||||||
|
# <BLANK LINE>
|
||||||
|
# <breaking change description + migration instructions>
|
||||||
|
# <BLANK LINE>
|
||||||
|
# <BLANK LINE>
|
||||||
|
# Fixes #<issue number>
|
||||||
|
# ```
|
||||||
|
#
|
||||||
|
# Breaking Change section should start with the phrase "BREAKING CHANGE: " followed by a summary of
|
||||||
|
# the breaking change, a blank line, and a detailed description of the breaking change that also
|
||||||
|
# includes migration instructions.
|
||||||
|
#
|
52
.ng-dev/commit-message.ts
Normal file
52
.ng-dev/commit-message.ts
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import {CommitMessageConfig} from '../dev-infra/commit-message/config';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The configuration for `ng-dev commit-message` commands.
|
||||||
|
*/
|
||||||
|
export const commitMessage: CommitMessageConfig = {
|
||||||
|
maxLineLength: 120,
|
||||||
|
minBodyLength: 20,
|
||||||
|
minBodyLengthTypeExcludes: ['docs'],
|
||||||
|
types: [
|
||||||
|
'build',
|
||||||
|
'ci',
|
||||||
|
'docs',
|
||||||
|
'feat',
|
||||||
|
'fix',
|
||||||
|
'perf',
|
||||||
|
'refactor',
|
||||||
|
'release',
|
||||||
|
'style',
|
||||||
|
'test',
|
||||||
|
],
|
||||||
|
scopes: [
|
||||||
|
'animations',
|
||||||
|
'bazel',
|
||||||
|
'benchpress',
|
||||||
|
'changelog',
|
||||||
|
'common',
|
||||||
|
'compiler',
|
||||||
|
'compiler-cli',
|
||||||
|
'core',
|
||||||
|
'dev-infra',
|
||||||
|
'docs-infra',
|
||||||
|
'elements',
|
||||||
|
'forms',
|
||||||
|
'http',
|
||||||
|
'language-service',
|
||||||
|
'localize',
|
||||||
|
'migrations',
|
||||||
|
'ngcc',
|
||||||
|
'packaging',
|
||||||
|
'platform-browser',
|
||||||
|
'platform-browser-dynamic',
|
||||||
|
'platform-server',
|
||||||
|
'platform-webworker',
|
||||||
|
'platform-webworker-dynamic',
|
||||||
|
'router',
|
||||||
|
'service-worker',
|
||||||
|
'upgrade',
|
||||||
|
've',
|
||||||
|
'zone.js',
|
||||||
|
]
|
||||||
|
};
|
@ -1,122 +1,8 @@
|
|||||||
import {MergeConfig} from '../dev-infra/pr/merge/config';
|
import {commitMessage} from './commit-message';
|
||||||
|
import {format} from './format';
|
||||||
|
import {github} from './github';
|
||||||
|
import {merge} from './merge';
|
||||||
|
|
||||||
// The configuration for `ng-dev commit-message` commands.
|
|
||||||
const commitMessage = {
|
|
||||||
'maxLength': 120,
|
|
||||||
'minBodyLength': 100,
|
|
||||||
'types': [
|
|
||||||
'build',
|
|
||||||
'ci',
|
|
||||||
'docs',
|
|
||||||
'feat',
|
|
||||||
'fix',
|
|
||||||
'perf',
|
|
||||||
'refactor',
|
|
||||||
'release',
|
|
||||||
'style',
|
|
||||||
'test',
|
|
||||||
],
|
|
||||||
'scopes': [
|
|
||||||
'animations',
|
|
||||||
'bazel',
|
|
||||||
'benchpress',
|
|
||||||
'changelog',
|
|
||||||
'common',
|
|
||||||
'compiler',
|
|
||||||
'compiler-cli',
|
|
||||||
'core',
|
|
||||||
'dev-infra',
|
|
||||||
'docs-infra',
|
|
||||||
'elements',
|
|
||||||
'forms',
|
|
||||||
'http',
|
|
||||||
'language-service',
|
|
||||||
'localize',
|
|
||||||
'migrations',
|
|
||||||
'ngcc',
|
|
||||||
'packaging',
|
|
||||||
'platform-browser',
|
|
||||||
'platform-browser-dynamic',
|
|
||||||
'platform-server',
|
|
||||||
'platform-webworker',
|
|
||||||
'platform-webworker-dynamic',
|
|
||||||
'router',
|
|
||||||
'service-worker',
|
|
||||||
'upgrade',
|
|
||||||
've',
|
|
||||||
'zone.js',
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
// The configuration for `ng-dev format` commands.
|
|
||||||
const format = {
|
|
||||||
'clang-format': {
|
|
||||||
'matchers': [
|
|
||||||
'dev-infra/**/*.{js,ts}',
|
|
||||||
'packages/**/*.{js,ts}',
|
|
||||||
'!packages/zone.js',
|
|
||||||
'!packages/common/locales/**/*.{js,ts}',
|
|
||||||
'!packages/common/src/i18n/available_locales.ts',
|
|
||||||
'!packages/common/src/i18n/currencies.ts',
|
|
||||||
'!packages/common/src/i18n/locale_en.ts',
|
|
||||||
'modules/benchmarks/**/*.{js,ts}',
|
|
||||||
'modules/playground/**/*.{js,ts}',
|
|
||||||
'tools/**/*.{js,ts}',
|
|
||||||
'!tools/gulp-tasks/cldr/extract.js',
|
|
||||||
'!tools/public_api_guard/**/*.d.ts',
|
|
||||||
'!tools/ts-api-guardian/test/fixtures/**',
|
|
||||||
'*.{js,ts}',
|
|
||||||
'!**/node_modules/**',
|
|
||||||
'!**/dist/**',
|
|
||||||
'!**/built/**',
|
|
||||||
'!shims_for_IE.js',
|
|
||||||
]
|
|
||||||
},
|
|
||||||
'buildifier': true
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Github metadata information for `ng-dev` commands. */
|
|
||||||
const github = {
|
|
||||||
owner: 'angular',
|
|
||||||
name: 'angular',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Configuration for the `ng-dev pr merge` command. The command can be used
|
|
||||||
// for merging upstream pull requests into branches based on a PR target label.
|
|
||||||
const merge = () => {
|
|
||||||
// TODO: resume dynamically determining patch branch
|
|
||||||
const patch = '10.0.x';
|
|
||||||
const config: MergeConfig = {
|
|
||||||
githubApiMerge: false,
|
|
||||||
claSignedLabel: 'cla: yes',
|
|
||||||
mergeReadyLabel: /^PR action: merge(-assistance)?/,
|
|
||||||
commitMessageFixupLabel: 'commit message fixup',
|
|
||||||
labels: [
|
|
||||||
{
|
|
||||||
pattern: 'PR target: master-only',
|
|
||||||
branches: ['master'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: 'PR target: patch-only',
|
|
||||||
branches: [patch],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: 'PR target: master & patch',
|
|
||||||
branches: ['master', patch],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
requiredBaseCommits: {
|
|
||||||
// PRs that target either `master` or the patch branch, need to be rebased
|
|
||||||
// on top of the latest commit message validation fix.
|
|
||||||
// These SHAs are the commits that update the required license text in the header.
|
|
||||||
'master': '5aeb9a4124922d8ac08eb73b8f322905a32b0b3a',
|
|
||||||
[patch]: '27b95ba64a5d99757f4042073fd1860e20e3ed24'
|
|
||||||
},
|
|
||||||
};
|
|
||||||
return config;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Export function to build ng-dev configuration object.
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
commitMessage,
|
commitMessage,
|
||||||
format,
|
format,
|
||||||
|
22
.ng-dev/format.ts
Normal file
22
.ng-dev/format.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import {FormatConfig} from '../dev-infra/format/config';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration for the `ng-dev format` command.
|
||||||
|
*/
|
||||||
|
export const format: FormatConfig = {
|
||||||
|
'clang-format': {
|
||||||
|
'matchers': [
|
||||||
|
'**/*.{js,ts}',
|
||||||
|
// TODO: burn down format failures and remove aio and integration exceptions.
|
||||||
|
'!aio/**',
|
||||||
|
'!integration/**',
|
||||||
|
// Both third_party and .yarn are directories containing copied code which should
|
||||||
|
// not be modified.
|
||||||
|
'!third_party/**',
|
||||||
|
'!.yarn/**',
|
||||||
|
// Do not format d.ts files as they are generated
|
||||||
|
'!**/*.d.ts',
|
||||||
|
]
|
||||||
|
},
|
||||||
|
'buildifier': true
|
||||||
|
};
|
15
.ng-dev/gitconfig
Normal file
15
.ng-dev/gitconfig
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# The file is inert unless it's explicitly included into the local git config via:
|
||||||
|
#
|
||||||
|
# ```
|
||||||
|
# git config --add include.path '../.ng-dev/gitconfig'
|
||||||
|
# ```
|
||||||
|
#
|
||||||
|
# Calling that command will append the following into `.git/config` of the current git workspace
|
||||||
|
# (i.e. $GIT_DIR, typically `angular/.git/config`):
|
||||||
|
#
|
||||||
|
# ```
|
||||||
|
# [include]
|
||||||
|
# path = ../.ng-dev/gitconfig
|
||||||
|
# ```
|
||||||
|
[commit]
|
||||||
|
template = .gitmessage
|
11
.ng-dev/github.ts
Normal file
11
.ng-dev/github.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import {GithubConfig} from '../dev-infra/utils/config';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Github configuration for the `ng-dev` command. This repository is used as
|
||||||
|
* remote for the merge script and other utilities like `ng-dev pr rebase`.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const github: GithubConfig = {
|
||||||
|
owner: 'angular',
|
||||||
|
name: 'angular'
|
||||||
|
};
|
38
.ng-dev/merge.ts
Normal file
38
.ng-dev/merge.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import {MergeConfig} from '../dev-infra/pr/merge/config';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration for the merge tool in `ng-dev`. This sets up the labels which
|
||||||
|
* are respected by the merge script (e.g. the target labels).
|
||||||
|
*/
|
||||||
|
export const merge = (): MergeConfig => {
|
||||||
|
// TODO: resume dynamically determining patch branch
|
||||||
|
const patch = '10.0.x';
|
||||||
|
return {
|
||||||
|
githubApiMerge: false,
|
||||||
|
claSignedLabel: 'cla: yes',
|
||||||
|
mergeReadyLabel: /^PR action: merge(-assistance)?/,
|
||||||
|
caretakerNoteLabel: 'PR action: merge-assistance',
|
||||||
|
commitMessageFixupLabel: 'commit message fixup',
|
||||||
|
labels: [
|
||||||
|
{
|
||||||
|
pattern: 'PR target: master-only',
|
||||||
|
branches: ['master'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pattern: 'PR target: patch-only',
|
||||||
|
branches: [patch],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pattern: 'PR target: master & patch',
|
||||||
|
branches: ['master', patch],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
requiredBaseCommits: {
|
||||||
|
// PRs that target either `master` or the patch branch, need to be rebased
|
||||||
|
// on top of the latest commit message validation fix.
|
||||||
|
// These SHAs are the commits that update the required license text in the header.
|
||||||
|
'master': '5aeb9a4124922d8ac08eb73b8f322905a32b0b3a',
|
||||||
|
[patch]: '27b95ba64a5d99757f4042073fd1860e20e3ed24'
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
152
.pullapprove.yml
152
.pullapprove.yml
@ -34,41 +34,8 @@
|
|||||||
####################################################################################
|
####################################################################################
|
||||||
# GitHub usernames
|
# GitHub usernames
|
||||||
####################################################################################
|
####################################################################################
|
||||||
# aikidave - Dave Shevitz
|
# See reviewer list under `required-minimum-review` group. Team member names and
|
||||||
# alan-agius4 - Alan Agius
|
# usernames are managed there.
|
||||||
# alxhub - Alex Rickabaugh
|
|
||||||
# AndrewKushnir - Andrew Kushnir
|
|
||||||
# andrewseguin - Andrew Seguin
|
|
||||||
# atscott - Andrew Scott
|
|
||||||
# ayazhafiz - Ayaz Hafiz
|
|
||||||
# clydin - Charles Lyding
|
|
||||||
# crisbeto - Kristiyan Kostadinov
|
|
||||||
# dennispbrown - Denny Brown
|
|
||||||
# devversion - Paul Gschwendtner
|
|
||||||
# dgp1130 - Doug Parker
|
|
||||||
# filipesilva - Filipe Silva
|
|
||||||
# gkalpak - Georgios Kalpakas
|
|
||||||
# gregmagolan - Greg Magolan
|
|
||||||
# IgorMinar - Igor Minar
|
|
||||||
# jbogarthyde - Judy Bogart
|
|
||||||
# jelbourn - Jeremy Elbourn
|
|
||||||
# JiaLiPassion - Jia Li
|
|
||||||
# JoostK - Joost Koehoorn
|
|
||||||
# josephperrott - Joey Perrott
|
|
||||||
# juleskremer - Jules Kremer
|
|
||||||
# kapunahelewong - Kapunahele Wong
|
|
||||||
# kara - Kara Erickson
|
|
||||||
# kyliau - Keen Yee Liau
|
|
||||||
# manughub - Manu Murthy
|
|
||||||
# matsko - Matias Niemela
|
|
||||||
# mgechev - Minko Gechev
|
|
||||||
# mhevery - Miško Hevery
|
|
||||||
# michaelprentice - Michael Prentice
|
|
||||||
# mmalerba - Miles Malerba
|
|
||||||
# petebacondarwin - Pete Bacon Darwin
|
|
||||||
# pkozlowski-opensource - Pawel Kozlowski
|
|
||||||
# robwormald - Rob Wormald
|
|
||||||
# StephenFluin - Stephen Fluin
|
|
||||||
|
|
||||||
|
|
||||||
####################################################################################
|
####################################################################################
|
||||||
@ -100,8 +67,16 @@ version: 3
|
|||||||
# Meta field that goes unused by PullApprove to allow for defining aliases to be
|
# Meta field that goes unused by PullApprove to allow for defining aliases to be
|
||||||
# used throughout the config.
|
# used throughout the config.
|
||||||
meta:
|
meta:
|
||||||
1: &can-be-global-approved "\"global-approvers\" not in groups.approved"
|
can-be-global-approved: &can-be-global-approved "\"global-approvers\" not in groups.approved"
|
||||||
2: &can-be-global-docs-approved "\"global-docs-approvers\" not in groups.approved"
|
can-be-global-docs-approved: &can-be-global-docs-approved "\"global-docs-approvers\" not in groups.approved"
|
||||||
|
defaults: &defaults
|
||||||
|
reviews:
|
||||||
|
# Authors provide their approval implicitly, this approval allows for a reviewer
|
||||||
|
# from a group not to need a review specifically for an area of the repository
|
||||||
|
# they own. This is coupled with the `required-minimum-review` group which requires
|
||||||
|
# that all PRs are reviewed by at least one team member who is not the author of
|
||||||
|
# the PR.
|
||||||
|
author_value: 1
|
||||||
|
|
||||||
# turn on 'draft' support
|
# turn on 'draft' support
|
||||||
# https://docs.pullapprove.com/config/github-api-version/
|
# https://docs.pullapprove.com/config/github-api-version/
|
||||||
@ -121,6 +96,55 @@ pullapprove_conditions:
|
|||||||
|
|
||||||
|
|
||||||
groups:
|
groups:
|
||||||
|
# =========================================================
|
||||||
|
# Require review on all PRs
|
||||||
|
#
|
||||||
|
# All PRs require at least one review. This rule will not
|
||||||
|
# request any reviewers, however will require that at least
|
||||||
|
# one review is provided before the group is satisfied.
|
||||||
|
# =========================================================
|
||||||
|
required-minimum-review:
|
||||||
|
reviews:
|
||||||
|
request: 0 # Do not request any reviews from the reviewer group
|
||||||
|
required: 1 # Require that all PRs have approval from at least one of the users in the group
|
||||||
|
author_value: 0 # The author of the PR cannot provide an approval for themself
|
||||||
|
reviewers:
|
||||||
|
users:
|
||||||
|
- aikidave # Dave Shevitz
|
||||||
|
- alan-agius4 # Alan Agius
|
||||||
|
- alxhub # Alex Rickabaugh
|
||||||
|
- AndrewKushnir # Andrew Kushnir
|
||||||
|
- andrewseguin # Andrew Seguin
|
||||||
|
- atscott # Andrew Scott
|
||||||
|
- ayazhafiz # Ayaz Hafiz
|
||||||
|
- clydin # Charles Lyding
|
||||||
|
- crisbeto # Kristiyan Kostadinov
|
||||||
|
- dennispbrown # Denny Brown
|
||||||
|
- devversion # Paul Gschwendtner
|
||||||
|
- dgp1130 # Doug Parker
|
||||||
|
- filipesilva # Filipe Silva
|
||||||
|
- gkalpak # Georgios Kalpakas
|
||||||
|
- gregmagolan # Greg Magolan
|
||||||
|
- IgorMinar # Igor Minar
|
||||||
|
- jbogarthyde # Judy Bogart
|
||||||
|
- jelbourn # Jeremy Elbourn
|
||||||
|
- JiaLiPassion # Jia Li
|
||||||
|
- JoostK # Joost Koehoorn
|
||||||
|
- josephperrott # Joey Perrott
|
||||||
|
- juleskremer # Jules Kremer
|
||||||
|
- kapunahelewong # Kapunahele Wong
|
||||||
|
- kara # Kara Erickson
|
||||||
|
- kyliau # Keen Yee Liau
|
||||||
|
- manughub # Manu Murthy
|
||||||
|
- matsko # Matias Niemela
|
||||||
|
- mgechev # Minko Gechev
|
||||||
|
- mhevery # Miško Hevery
|
||||||
|
- michaelprentice # Michael Prentice
|
||||||
|
- mmalerba # Miles Malerba
|
||||||
|
- petebacondarwin # Pete Bacon Darwin
|
||||||
|
- pkozlowski-opensource # Pawel Kozlowski
|
||||||
|
- StephenFluin # Stephen Fluin
|
||||||
|
|
||||||
# =========================================================
|
# =========================================================
|
||||||
# Global Approvers
|
# Global Approvers
|
||||||
#
|
#
|
||||||
@ -161,6 +185,7 @@ groups:
|
|||||||
# Framework: Animations
|
# Framework: Animations
|
||||||
# =========================================================
|
# =========================================================
|
||||||
fw-animations:
|
fw-animations:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -185,6 +210,7 @@ groups:
|
|||||||
# Framework: Compiler
|
# Framework: Compiler
|
||||||
# =========================================================
|
# =========================================================
|
||||||
fw-compiler:
|
fw-compiler:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -209,6 +235,7 @@ groups:
|
|||||||
# Framework: Compiler / ngcc
|
# Framework: Compiler / ngcc
|
||||||
# =========================================================
|
# =========================================================
|
||||||
fw-ngcc:
|
fw-ngcc:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -225,6 +252,7 @@ groups:
|
|||||||
# Framework: Migrations
|
# Framework: Migrations
|
||||||
# =========================================================
|
# =========================================================
|
||||||
fw-migrations:
|
fw-migrations:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -240,6 +268,7 @@ groups:
|
|||||||
# Framework: Core
|
# Framework: Core
|
||||||
# =========================================================
|
# =========================================================
|
||||||
fw-core:
|
fw-core:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -333,6 +362,7 @@ groups:
|
|||||||
'aio/content/images/guide/pipes/**',
|
'aio/content/images/guide/pipes/**',
|
||||||
'aio/content/guide/providers.md',
|
'aio/content/guide/providers.md',
|
||||||
'aio/content/examples/providers/**',
|
'aio/content/examples/providers/**',
|
||||||
|
'aio/content/images/guide/providers/**',
|
||||||
'aio/content/guide/singleton-services.md',
|
'aio/content/guide/singleton-services.md',
|
||||||
'aio/content/guide/set-document-title.md',
|
'aio/content/guide/set-document-title.md',
|
||||||
'aio/content/examples/set-document-title/**',
|
'aio/content/examples/set-document-title/**',
|
||||||
@ -359,6 +389,7 @@ groups:
|
|||||||
# Framework: Http
|
# Framework: Http
|
||||||
# =========================================================
|
# =========================================================
|
||||||
fw-http:
|
fw-http:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -380,6 +411,7 @@ groups:
|
|||||||
# Framework: Elements
|
# Framework: Elements
|
||||||
# =========================================================
|
# =========================================================
|
||||||
fw-elements:
|
fw-elements:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -400,6 +432,7 @@ groups:
|
|||||||
# Framework: Forms
|
# Framework: Forms
|
||||||
# =========================================================
|
# =========================================================
|
||||||
fw-forms:
|
fw-forms:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -432,6 +465,7 @@ groups:
|
|||||||
# Framework: i18n
|
# Framework: i18n
|
||||||
# =========================================================
|
# =========================================================
|
||||||
fw-i18n:
|
fw-i18n:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -465,6 +499,7 @@ groups:
|
|||||||
# Framework: Platform Server
|
# Framework: Platform Server
|
||||||
# =========================================================
|
# =========================================================
|
||||||
fw-platform-server:
|
fw-platform-server:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -484,6 +519,7 @@ groups:
|
|||||||
# Framework: Router
|
# Framework: Router
|
||||||
# =========================================================
|
# =========================================================
|
||||||
fw-router:
|
fw-router:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -493,6 +529,7 @@ groups:
|
|||||||
'packages/examples/router/**',
|
'packages/examples/router/**',
|
||||||
'aio/content/guide/router.md',
|
'aio/content/guide/router.md',
|
||||||
'aio/content/guide/router-tutorial.md',
|
'aio/content/guide/router-tutorial.md',
|
||||||
|
'aio/content/guide/router-tutorial-toh.md',
|
||||||
'aio/content/examples/router-tutorial/**',
|
'aio/content/examples/router-tutorial/**',
|
||||||
'aio/content/examples/router/**',
|
'aio/content/examples/router/**',
|
||||||
'aio/content/images/guide/router/**'
|
'aio/content/images/guide/router/**'
|
||||||
@ -506,6 +543,7 @@ groups:
|
|||||||
# Framework: Service Worker
|
# Framework: Service Worker
|
||||||
# =========================================================
|
# =========================================================
|
||||||
fw-service-worker:
|
fw-service-worker:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -533,6 +571,7 @@ groups:
|
|||||||
# Framework: Upgrade
|
# Framework: Upgrade
|
||||||
# =========================================================
|
# =========================================================
|
||||||
fw-upgrade:
|
fw-upgrade:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -563,6 +602,7 @@ groups:
|
|||||||
# Framework: Testing
|
# Framework: Testing
|
||||||
# =========================================================
|
# =========================================================
|
||||||
fw-testing:
|
fw-testing:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -570,6 +610,14 @@ groups:
|
|||||||
contains_any_globs(files.exclude('packages/compiler-cli/**'), [
|
contains_any_globs(files.exclude('packages/compiler-cli/**'), [
|
||||||
'**/testing/**',
|
'**/testing/**',
|
||||||
'aio/content/guide/testing.md',
|
'aio/content/guide/testing.md',
|
||||||
|
'aio/content/guide/test-debugging.md',
|
||||||
|
'aio/content/guide/testing-attribute-directives.md',
|
||||||
|
'aio/content/guide/testing-code-coverage.md',
|
||||||
|
'aio/content/guide/testing-components-basics.md',
|
||||||
|
'aio/content/guide/testing-components-scenarios.md',
|
||||||
|
'aio/content/guide/testing-pipes.md',
|
||||||
|
'aio/content/guide/testing-services.md',
|
||||||
|
'aio/content/guide/testing-utility-apis.md',
|
||||||
'aio/content/examples/testing/**',
|
'aio/content/examples/testing/**',
|
||||||
'aio/content/images/guide/testing/**'
|
'aio/content/images/guide/testing/**'
|
||||||
])
|
])
|
||||||
@ -584,6 +632,7 @@ groups:
|
|||||||
# Framework: Benchmarks
|
# Framework: Benchmarks
|
||||||
# =========================================================
|
# =========================================================
|
||||||
fw-benchmarks:
|
fw-benchmarks:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- >
|
- >
|
||||||
@ -600,6 +649,7 @@ groups:
|
|||||||
# Framework: Playground
|
# Framework: Playground
|
||||||
# =========================================================
|
# =========================================================
|
||||||
fw-playground:
|
fw-playground:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- >
|
- >
|
||||||
@ -617,6 +667,7 @@ groups:
|
|||||||
# Framework: Security
|
# Framework: Security
|
||||||
# =========================================================
|
# =========================================================
|
||||||
fw-security:
|
fw-security:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -646,6 +697,7 @@ groups:
|
|||||||
# Bazel
|
# Bazel
|
||||||
# =========================================================
|
# =========================================================
|
||||||
bazel:
|
bazel:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -664,6 +716,7 @@ groups:
|
|||||||
# Language Service
|
# Language Service
|
||||||
# =========================================================
|
# =========================================================
|
||||||
language-service:
|
language-service:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -683,6 +736,7 @@ groups:
|
|||||||
# zone.js
|
# zone.js
|
||||||
# =========================================================
|
# =========================================================
|
||||||
zone-js:
|
zone-js:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -701,6 +755,7 @@ groups:
|
|||||||
# Benchpress
|
# Benchpress
|
||||||
# =========================================================
|
# =========================================================
|
||||||
benchpress:
|
benchpress:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -718,6 +773,7 @@ groups:
|
|||||||
# Integration Tests
|
# Integration Tests
|
||||||
# =========================================================
|
# =========================================================
|
||||||
integration-tests:
|
integration-tests:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- >
|
- >
|
||||||
@ -735,6 +791,7 @@ groups:
|
|||||||
# Docs: Gettings Started & Tutorial
|
# Docs: Gettings Started & Tutorial
|
||||||
# =========================================================
|
# =========================================================
|
||||||
docs-getting-started-and-tutorial:
|
docs-getting-started-and-tutorial:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -767,6 +824,7 @@ groups:
|
|||||||
# Docs: Marketing
|
# Docs: Marketing
|
||||||
# =========================================================
|
# =========================================================
|
||||||
docs-marketing:
|
docs-marketing:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -789,6 +847,7 @@ groups:
|
|||||||
# Docs: Observables
|
# Docs: Observables
|
||||||
# =========================================================
|
# =========================================================
|
||||||
docs-observables:
|
docs-observables:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -814,6 +873,7 @@ groups:
|
|||||||
# Docs: Packaging, Tooling, Releasing
|
# Docs: Packaging, Tooling, Releasing
|
||||||
# =========================================================
|
# =========================================================
|
||||||
docs-packaging-and-releasing:
|
docs-packaging-and-releasing:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -833,7 +893,7 @@ groups:
|
|||||||
'aio/content/guide/migration-localize.md',
|
'aio/content/guide/migration-localize.md',
|
||||||
'aio/content/guide/migration-module-with-providers.md',
|
'aio/content/guide/migration-module-with-providers.md',
|
||||||
'aio/content/guide/static-query-migration.md',
|
'aio/content/guide/static-query-migration.md',
|
||||||
'aio/content/guide/updating-to-version-9.md',
|
'aio/content/guide/updating-to-version-10.md',
|
||||||
'aio/content/guide/ivy-compatibility.md',
|
'aio/content/guide/ivy-compatibility.md',
|
||||||
'aio/content/guide/ivy-compatibility-examples.md'
|
'aio/content/guide/ivy-compatibility-examples.md'
|
||||||
])
|
])
|
||||||
@ -873,6 +933,7 @@ groups:
|
|||||||
# Docs: CLI
|
# Docs: CLI
|
||||||
# =========================================================
|
# =========================================================
|
||||||
docs-cli:
|
docs-cli:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -889,8 +950,12 @@ groups:
|
|||||||
'aio/content/images/guide/deployment/**',
|
'aio/content/images/guide/deployment/**',
|
||||||
'aio/content/guide/file-structure.md',
|
'aio/content/guide/file-structure.md',
|
||||||
'aio/content/guide/ivy.md',
|
'aio/content/guide/ivy.md',
|
||||||
|
'aio/content/guide/strict-mode.md',
|
||||||
'aio/content/guide/web-worker.md',
|
'aio/content/guide/web-worker.md',
|
||||||
'aio/content/guide/workspace-config.md',
|
'aio/content/guide/workspace-config.md',
|
||||||
|
'aio/content/guide/migration-solution-style-tsconfig.md',
|
||||||
|
'aio/content/guide/migration-update-module-and-target-compiler-options.md',
|
||||||
|
'aio/content/guide/migration-update-libraries-tslib.md',
|
||||||
])
|
])
|
||||||
reviewers:
|
reviewers:
|
||||||
users:
|
users:
|
||||||
@ -903,6 +968,7 @@ groups:
|
|||||||
# Docs: CLI Libraries
|
# Docs: CLI Libraries
|
||||||
# =========================================================
|
# =========================================================
|
||||||
docs-libraries:
|
docs-libraries:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -923,6 +989,7 @@ groups:
|
|||||||
# Docs: Schematics
|
# Docs: Schematics
|
||||||
# =========================================================
|
# =========================================================
|
||||||
docs-schematics:
|
docs-schematics:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -945,6 +1012,7 @@ groups:
|
|||||||
# Docs-infra
|
# Docs-infra
|
||||||
# =========================================================
|
# =========================================================
|
||||||
docs-infra:
|
docs-infra:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- *can-be-global-docs-approved
|
- *can-be-global-docs-approved
|
||||||
@ -974,10 +1042,11 @@ groups:
|
|||||||
# Dev-infra
|
# Dev-infra
|
||||||
# =========================================================
|
# =========================================================
|
||||||
dev-infra:
|
dev-infra:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- >
|
- >
|
||||||
contains_any_globs(files.exclude("CHANGELOG.md"), [
|
contains_any_globs(files.exclude("CHANGELOG.md").exclude("packages/compiler-cli/**/BUILD.bazel"), [
|
||||||
'*',
|
'*',
|
||||||
'.circleci/**',
|
'.circleci/**',
|
||||||
'.devcontainer/**',
|
'.devcontainer/**',
|
||||||
@ -1038,6 +1107,7 @@ groups:
|
|||||||
# Public API
|
# Public API
|
||||||
# =========================================================
|
# =========================================================
|
||||||
public-api:
|
public-api:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- >
|
- >
|
||||||
@ -1066,6 +1136,7 @@ groups:
|
|||||||
# Size tracking
|
# Size tracking
|
||||||
# ================================================
|
# ================================================
|
||||||
size-tracking:
|
size-tracking:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- >
|
- >
|
||||||
@ -1088,6 +1159,7 @@ groups:
|
|||||||
# Circular dependencies
|
# Circular dependencies
|
||||||
# ================================================
|
# ================================================
|
||||||
circular-dependencies:
|
circular-dependencies:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- >
|
- >
|
||||||
@ -1110,6 +1182,7 @@ groups:
|
|||||||
# Code Ownership
|
# Code Ownership
|
||||||
# =========================================================
|
# =========================================================
|
||||||
code-ownership:
|
code-ownership:
|
||||||
|
<<: *defaults
|
||||||
conditions:
|
conditions:
|
||||||
- *can-be-global-approved
|
- *can-be-global-approved
|
||||||
- >
|
- >
|
||||||
@ -1125,6 +1198,7 @@ groups:
|
|||||||
# Catch all for if no groups match the code change
|
# Catch all for if no groups match the code change
|
||||||
# ====================================================
|
# ====================================================
|
||||||
fallback:
|
fallback:
|
||||||
|
<<: *defaults
|
||||||
# A group is considered to be `active` for a PR if at least one of group's
|
# A group is considered to be `active` for a PR if at least one of group's
|
||||||
# conditions matches the PR.
|
# conditions matches the PR.
|
||||||
#
|
#
|
||||||
|
@ -24,7 +24,7 @@ filegroup(
|
|||||||
"//packages/zone.js/dist:zone-testing.js",
|
"//packages/zone.js/dist:zone-testing.js",
|
||||||
"//packages/zone.js/dist:task-tracking.js",
|
"//packages/zone.js/dist:task-tracking.js",
|
||||||
"//:test-events.js",
|
"//:test-events.js",
|
||||||
"//:shims_for_IE.js",
|
"//:third_party/shims_for_IE.js",
|
||||||
# Including systemjs because it defines `__eval`, which produces correct stack traces.
|
# Including systemjs because it defines `__eval`, which produces correct stack traces.
|
||||||
"@npm//:node_modules/systemjs/dist/system.src.js",
|
"@npm//:node_modules/systemjs/dist/system.src.js",
|
||||||
"@npm//:node_modules/reflect-metadata/Reflect.js",
|
"@npm//:node_modules/reflect-metadata/Reflect.js",
|
||||||
|
808
CHANGELOG.md
808
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
298
CONTRIBUTING.md
298
CONTRIBUTING.md
@ -1,7 +1,7 @@
|
|||||||
# Contributing to Angular
|
# Contributing to Angular
|
||||||
|
|
||||||
We would love for you to contribute to Angular and help make it even better than it is
|
We would love for you to contribute to Angular and help make it even better than it is today!
|
||||||
today! As a contributor, here are the guidelines we would like you to follow:
|
As a contributor, here are the guidelines we would like you to follow:
|
||||||
|
|
||||||
- [Code of Conduct](#coc)
|
- [Code of Conduct](#coc)
|
||||||
- [Question or Problem?](#question)
|
- [Question or Problem?](#question)
|
||||||
@ -12,50 +12,63 @@ today! As a contributor, here are the guidelines we would like you to follow:
|
|||||||
- [Commit Message Guidelines](#commit)
|
- [Commit Message Guidelines](#commit)
|
||||||
- [Signing the CLA](#cla)
|
- [Signing the CLA](#cla)
|
||||||
|
|
||||||
|
|
||||||
## <a name="coc"></a> Code of Conduct
|
## <a name="coc"></a> Code of Conduct
|
||||||
Help us keep Angular open and inclusive. Please read and follow our [Code of Conduct][coc].
|
|
||||||
|
Help us keep Angular open and inclusive.
|
||||||
|
Please read and follow our [Code of Conduct][coc].
|
||||||
|
|
||||||
|
|
||||||
## <a name="question"></a> Got a Question or Problem?
|
## <a name="question"></a> Got a Question or Problem?
|
||||||
|
|
||||||
Do not open issues for general support questions as we want to keep GitHub issues for bug reports and feature requests. You've got much better chances of getting your question answered on [Stack Overflow](https://stackoverflow.com/questions/tagged/angular) where the questions should be tagged with tag `angular`.
|
Do not open issues for general support questions as we want to keep GitHub issues for bug reports and feature requests.
|
||||||
|
Instead, we recommend using [Stack Overflow](https://stackoverflow.com/questions/tagged/angular) to ask support-related questions. When creating a new question on Stack Overflow, make sure to add the `angular` tag.
|
||||||
|
|
||||||
Stack Overflow is a much better place to ask questions since:
|
Stack Overflow is a much better place to ask questions since:
|
||||||
|
|
||||||
- there are thousands of people willing to help on Stack Overflow
|
- there are thousands of people willing to help on Stack Overflow
|
||||||
- questions and answers stay available for public viewing so your question / answer might help someone else
|
- questions and answers stay available for public viewing so your question/answer might help someone else
|
||||||
- Stack Overflow's voting system assures that the best answers are prominently visible.
|
- Stack Overflow's voting system assures that the best answers are prominently visible.
|
||||||
|
|
||||||
To save your and our time, we will systematically close all issues that are requests for general support and redirect people to Stack Overflow.
|
To save your and our time, we will systematically close all issues that are requests for general support and redirect people to Stack Overflow.
|
||||||
|
|
||||||
If you would like to chat about the question in real-time, you can reach out via [our gitter channel][gitter].
|
If you would like to chat about the question in real-time, you can reach out via [our gitter channel][gitter].
|
||||||
|
|
||||||
|
|
||||||
## <a name="issue"></a> Found a Bug?
|
## <a name="issue"></a> Found a Bug?
|
||||||
If you find a bug in the source code, you can help us by
|
|
||||||
[submitting an issue](#submit-issue) to our [GitHub Repository][github]. Even better, you can
|
If you find a bug in the source code, you can help us by [submitting an issue](#submit-issue) to our [GitHub Repository][github].
|
||||||
[submit a Pull Request](#submit-pr) with a fix.
|
Even better, you can [submit a Pull Request](#submit-pr) with a fix.
|
||||||
|
|
||||||
|
|
||||||
## <a name="feature"></a> Missing a Feature?
|
## <a name="feature"></a> Missing a Feature?
|
||||||
You can *request* a new feature by [submitting an issue](#submit-issue) to our GitHub
|
You can *request* a new feature by [submitting an issue](#submit-issue) to our GitHub Repository.
|
||||||
Repository. If you would like to *implement* a new feature, please submit an issue with
|
If you would like to *implement* a new feature, please consider the size of the change in order to determine the right steps to proceed:
|
||||||
a proposal for your work first, to be sure that we can use it.
|
|
||||||
Please consider what kind of change it is:
|
* For a **Major Feature**, first open an issue and outline your proposal so that it can be discussed.
|
||||||
|
This process allows us to better coordinate our efforts, prevent duplication of work, and help you to craft the change so that it is successfully accepted into the project.
|
||||||
|
|
||||||
|
**Note**: Adding a new topic to the documentation, or significantly re-writing a topic, counts as a major feature.
|
||||||
|
|
||||||
* For a **Major Feature**, first open an issue and outline your proposal so that it can be
|
|
||||||
discussed. This will also allow us to better coordinate our efforts, prevent duplication of work,
|
|
||||||
and help you to craft the change so that it is successfully accepted into the project.
|
|
||||||
* **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr).
|
* **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr).
|
||||||
|
|
||||||
|
|
||||||
## <a name="submit"></a> Submission Guidelines
|
## <a name="submit"></a> Submission Guidelines
|
||||||
|
|
||||||
|
|
||||||
### <a name="submit-issue"></a> Submitting an Issue
|
### <a name="submit-issue"></a> Submitting an Issue
|
||||||
|
|
||||||
Before you submit an issue, please search the issue tracker, maybe an issue for your problem already exists and the discussion might inform you of workarounds readily available.
|
Before you submit an issue, please search the issue tracker, maybe an issue for your problem already exists and the discussion might inform you of workarounds readily available.
|
||||||
|
|
||||||
We want to fix all the issues as soon as possible, but before fixing a bug we need to reproduce and confirm it. In order to reproduce bugs, we will systematically ask you to provide a minimal reproduction. Having a minimal reproducible scenario gives us a wealth of important information without going back & forth to you with additional questions.
|
We want to fix all the issues as soon as possible, but before fixing a bug we need to reproduce and confirm it.
|
||||||
|
In order to reproduce bugs, we require that you provide a minimal reproduction.
|
||||||
|
Having a minimal reproducible scenario gives us a wealth of important information without going back and forth to you with additional questions.
|
||||||
|
|
||||||
A minimal reproduction allows us to quickly confirm a bug (or point out a coding problem) as well as confirm that we are fixing the right problem.
|
A minimal reproduction allows us to quickly confirm a bug (or point out a coding problem) as well as confirm that we are fixing the right problem.
|
||||||
|
|
||||||
We will be insisting on a minimal reproduction scenario in order to save maintainers time and ultimately be able to fix more bugs. Interestingly, from our experience, users often find coding problems themselves while preparing a minimal reproduction. We understand that sometimes it might be hard to extract essential bits of code from a larger codebase but we really need to isolate the problem before we can fix it.
|
We require a minimal reproduction to save maintainers' time and ultimately be able to fix more bugs.
|
||||||
|
Often, developers find coding problems themselves while preparing a minimal reproduction.
|
||||||
|
We understand that sometimes it might be hard to extract essential bits of code from a larger codebase but we really need to isolate the problem before we can fix it.
|
||||||
|
|
||||||
Unfortunately, we are not able to investigate / fix bugs without a minimal reproduction, so if we don't hear back from you, we are going to close an issue that doesn't have enough info to be reproduced.
|
Unfortunately, we are not able to investigate / fix bugs without a minimal reproduction, so if we don't hear back from you, we are going to close an issue that doesn't have enough info to be reproduced.
|
||||||
|
|
||||||
@ -63,57 +76,66 @@ You can file new issues by selecting from our [new issue templates](https://gith
|
|||||||
|
|
||||||
|
|
||||||
### <a name="submit-pr"></a> Submitting a Pull Request (PR)
|
### <a name="submit-pr"></a> Submitting a Pull Request (PR)
|
||||||
|
|
||||||
Before you submit your Pull Request (PR) consider the following guidelines:
|
Before you submit your Pull Request (PR) consider the following guidelines:
|
||||||
|
|
||||||
1. Search [GitHub](https://github.com/angular/angular/pulls) for an open or closed PR
|
1. Search [GitHub](https://github.com/angular/angular/pulls) for an open or closed PR that relates to your submission.
|
||||||
that relates to your submission. You don't want to duplicate effort.
|
You don't want to duplicate existing efforts.
|
||||||
1. Be sure that an issue describes the problem you're fixing, or documents the design for the feature you'd like to add.
|
|
||||||
Discussing the design up front helps to ensure that we're ready to accept your work.
|
2. Be sure that an issue describes the problem you're fixing, or documents the design for the feature you'd like to add.
|
||||||
1. Please sign our [Contributor License Agreement (CLA)](#cla) before sending PRs.
|
Discussing the design upfront helps to ensure that we're ready to accept your work.
|
||||||
We cannot accept code without this. Make sure you sign with the primary email address of the Git identity that has been granted access to the Angular repository.
|
|
||||||
1. Fork the angular/angular repo.
|
3. Please sign our [Contributor License Agreement (CLA)](#cla) before sending PRs.
|
||||||
1. Make your changes in a new git branch:
|
We cannot accept code without a signed CLA.
|
||||||
|
Make sure you author all contributed Git commits with email address associated with your CLA signature.
|
||||||
|
|
||||||
|
4. Fork the angular/angular repo.
|
||||||
|
|
||||||
|
5. Make your changes in a new git branch:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
git checkout -b my-fix-branch master
|
git checkout -b my-fix-branch master
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Create your patch, **including appropriate test cases**.
|
6. Create your patch, **including appropriate test cases**.
|
||||||
1. Follow our [Coding Rules](#rules).
|
|
||||||
1. Run the full Angular test suite, as described in the [developer documentation][dev-doc],
|
7. Follow our [Coding Rules](#rules).
|
||||||
and ensure that all tests pass.
|
|
||||||
1. Commit your changes using a descriptive commit message that follows our
|
8. Run the full Angular test suite, as described in the [developer documentation][dev-doc], and ensure that all tests pass.
|
||||||
[commit message conventions](#commit). Adherence to these conventions
|
|
||||||
is necessary because release notes are automatically generated from these messages.
|
9. Commit your changes using a descriptive commit message that follows our [commit message conventions](#commit).
|
||||||
|
Adherence to these conventions is necessary because release notes are automatically generated from these messages.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
git commit -a
|
git commit -a
|
||||||
```
|
```
|
||||||
Note: the optional commit `-a` command line option will automatically "add" and "rm" edited files.
|
Note: the optional commit `-a` command line option will automatically "add" and "rm" edited files.
|
||||||
|
|
||||||
1. Push your branch to GitHub:
|
10. Push your branch to GitHub:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
git push origin my-fix-branch
|
git push origin my-fix-branch
|
||||||
```
|
```
|
||||||
|
|
||||||
1. In GitHub, send a pull request to `angular:master`.
|
11. In GitHub, send a pull request to `angular:master`.
|
||||||
* If we suggest changes then:
|
|
||||||
* Make the required updates.
|
|
||||||
* Re-run the Angular test suites to ensure tests are still passing.
|
|
||||||
* Rebase your branch and force push to your GitHub repository (this will update your Pull Request):
|
|
||||||
|
|
||||||
```shell
|
If we ask for changes via code reviews then:
|
||||||
git rebase master -i
|
|
||||||
git push -f
|
* Make the required updates.
|
||||||
```
|
* Re-run the Angular test suites to ensure tests are still passing.
|
||||||
|
* Rebase your branch and force push to your GitHub repository (this will update your Pull Request):
|
||||||
|
|
||||||
|
```shell
|
||||||
|
git rebase master -i
|
||||||
|
git push -f
|
||||||
|
```
|
||||||
|
|
||||||
That's it! Thank you for your contribution!
|
That's it! Thank you for your contribution!
|
||||||
|
|
||||||
|
|
||||||
#### After your pull request is merged
|
#### After your pull request is merged
|
||||||
|
|
||||||
After your pull request is merged, you can safely delete your branch and pull the changes
|
After your pull request is merged, you can safely delete your branch and pull the changes from the main (upstream) repository:
|
||||||
from the main (upstream) repository:
|
|
||||||
|
|
||||||
* Delete the remote branch on GitHub either through the GitHub web UI or your local shell as follows:
|
* Delete the remote branch on GitHub either through the GitHub web UI or your local shell as follows:
|
||||||
|
|
||||||
@ -139,55 +161,66 @@ from the main (upstream) repository:
|
|||||||
git pull --ff upstream master
|
git pull --ff upstream master
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## <a name="rules"></a> Coding Rules
|
## <a name="rules"></a> Coding Rules
|
||||||
To ensure consistency throughout the source code, keep these rules in mind as you are working:
|
To ensure consistency throughout the source code, keep these rules in mind as you are working:
|
||||||
|
|
||||||
* All features or bug fixes **must be tested** by one or more specs (unit-tests).
|
* All features or bug fixes **must be tested** by one or more specs (unit-tests).
|
||||||
* All public API methods **must be documented**. (Details TBC).
|
* All public API methods **must be documented**.
|
||||||
* We follow [Google's JavaScript Style Guide][js-style-guide], but wrap all code at
|
* We follow [Google's JavaScript Style Guide][js-style-guide], but wrap all code at **100 characters**.
|
||||||
**100 characters**. An automated formatter is available, see
|
|
||||||
[DEVELOPER.md](docs/DEVELOPER.md#clang-format).
|
|
||||||
|
|
||||||
## <a name="commit"></a> Commit Message Guidelines
|
An automated formatter is available, see [DEVELOPER.md](docs/DEVELOPER.md#clang-format).
|
||||||
|
|
||||||
We have very precise rules over how our git commit messages can be formatted. This leads to **more
|
|
||||||
readable messages** that are easy to follow when looking through the **project history**. But also,
|
|
||||||
we use the git commit messages to **generate the Angular change log**.
|
|
||||||
|
|
||||||
### Commit Message Format
|
## <a name="commit"></a> Commit Message Format
|
||||||
Each commit message consists of a **header**, a **body** and a **footer**. The header has a special
|
|
||||||
format that includes a **type**, a **scope** and a **subject**:
|
*This specification is inspired and supersedes the [AngularJS commit message format][commit-message-format].*
|
||||||
|
|
||||||
|
We have very precise rules over how our Git commit messages must be formatted.
|
||||||
|
This format leads to **easier to read commit history**.
|
||||||
|
|
||||||
|
Each commit message consists of a **header**, a **body**, and a **footer**.
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
<type>(<scope>): <subject>
|
<header>
|
||||||
<BLANK LINE>
|
<BLANK LINE>
|
||||||
<body>
|
<body>
|
||||||
<BLANK LINE>
|
<BLANK LINE>
|
||||||
<footer>
|
<footer>
|
||||||
```
|
```
|
||||||
|
|
||||||
The **header** is mandatory and the **scope** of the header is optional.
|
The `header` is mandatory and must conform to the [Commit Message Header](#commit-header) format.
|
||||||
|
|
||||||
Any line of the commit message cannot be longer than 100 characters! This allows the message to be easier
|
The `body` is mandatory for all commits except for those of scope "docs".
|
||||||
to read on GitHub as well as in various git tools.
|
When the body is required it must be at least 20 characters long.
|
||||||
|
|
||||||
The footer should contain a [closing reference to an issue](https://help.github.com/articles/closing-issues-via-commit-messages/) if any.
|
The `footer` is optional.
|
||||||
|
|
||||||
Samples: (even more [samples](https://github.com/angular/angular/commits/master))
|
Any line of the commit message cannot be longer than 100 characters.
|
||||||
|
|
||||||
|
|
||||||
|
#### <a href="commit-header"></a>Commit Message Header
|
||||||
|
|
||||||
```
|
```
|
||||||
docs(changelog): update changelog to beta.5
|
<type>(<scope>): <short summary>
|
||||||
```
|
│ │ │
|
||||||
```
|
│ │ └─⫸ Summary in present tense. Not capitalized. No period at the end.
|
||||||
fix(release): need to depend on latest rxjs and zone.js
|
│ │
|
||||||
|
│ └─⫸ Commit Scope: animations|bazel|benchpress|common|compiler|compiler-cli|core|
|
||||||
The version in our package.json gets copied to the one we publish, and users need the latest of these.
|
│ elements|forms|http|language-service|localize|platform-browser|
|
||||||
|
│ platform-browser-dynamic|platform-server|platform-webworker|
|
||||||
|
│ platform-webworker-dynamic|router|service-worker|upgrade|zone.js|
|
||||||
|
│ packaging|changelog|dev-infra|docs-infra|migrations|ngcc|ve
|
||||||
|
│
|
||||||
|
└─⫸ Commit Type: build|ci|docs|feat|fix|perf|refactor|style|test
|
||||||
```
|
```
|
||||||
|
|
||||||
### Revert
|
The `<type>` and `<summary>` fields are mandatory, the `(<scope>)` field is optional.
|
||||||
If the commit reverts a previous commit, it should begin with `revert: `, followed by the header of the reverted commit. In the body it should say: `This reverts commit <hash>.`, where the hash is the SHA of the commit being reverted.
|
|
||||||
|
|
||||||
|
##### Type
|
||||||
|
|
||||||
### Type
|
|
||||||
Must be one of the following:
|
Must be one of the following:
|
||||||
|
|
||||||
* **build**: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
|
* **build**: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
|
||||||
@ -200,67 +233,95 @@ Must be one of the following:
|
|||||||
* **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
|
* **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
|
||||||
* **test**: Adding missing tests or correcting existing tests
|
* **test**: Adding missing tests or correcting existing tests
|
||||||
|
|
||||||
### Scope
|
|
||||||
|
##### Scope
|
||||||
The scope should be the name of the npm package affected (as perceived by the person reading the changelog generated from commit messages).
|
The scope should be the name of the npm package affected (as perceived by the person reading the changelog generated from commit messages).
|
||||||
|
|
||||||
The following is the list of supported scopes:
|
The following is the list of supported scopes:
|
||||||
|
|
||||||
* **animations**
|
* `animations`
|
||||||
* **bazel**
|
* `bazel`
|
||||||
* **benchpress**
|
* `benchpress`
|
||||||
* **common**
|
* `common`
|
||||||
* **compiler**
|
* `compiler`
|
||||||
* **compiler-cli**
|
* `compiler-cli`
|
||||||
* **core**
|
* `core`
|
||||||
* **elements**
|
* `elements`
|
||||||
* **forms**
|
* `forms`
|
||||||
* **http**
|
* `http`
|
||||||
* **language-service**
|
* `language-service`
|
||||||
* **localize**
|
* `localize`
|
||||||
* **platform-browser**
|
* `platform-browser`
|
||||||
* **platform-browser-dynamic**
|
* `platform-browser-dynamic`
|
||||||
* **platform-server**
|
* `platform-server`
|
||||||
* **platform-webworker**
|
* `platform-webworker`
|
||||||
* **platform-webworker-dynamic**
|
* `platform-webworker-dynamic`
|
||||||
* **router**
|
* `router`
|
||||||
* **service-worker**
|
* `service-worker`
|
||||||
* **upgrade**
|
* `upgrade`
|
||||||
* **zone.js**
|
* `zone.js`
|
||||||
|
|
||||||
There are currently a few exceptions to the "use package name" rule:
|
There are currently a few exceptions to the "use package name" rule:
|
||||||
|
|
||||||
* **packaging**: used for changes that change the npm package layout in all of our packages, e.g.
|
* `packaging`: used for changes that change the npm package layout in all of our packages, e.g. public path changes, package.json changes done to all packages, d.ts file/format changes, changes to bundles, etc.
|
||||||
public path changes, package.json changes done to all packages, d.ts file/format changes, changes
|
|
||||||
to bundles, etc.
|
|
||||||
* **changelog**: used for updating the release notes in CHANGELOG.md
|
|
||||||
* **docs-infra**: used for docs-app (angular.io) related changes within the /aio directory of the
|
|
||||||
repo
|
|
||||||
* **dev-infra**: used for dev-infra related changes within the directories /scripts, /tools and /dev-infra
|
|
||||||
* **migrations**: used for changes to the `ng update` migrations.
|
|
||||||
* **ngcc**: used for changes to the [Angular Compatibility Compiler](./packages/compiler-cli/ngcc/README.md)
|
|
||||||
* **ve**: used for changes specific to ViewEngine (legacy compiler/renderer).
|
|
||||||
* none/empty string: useful for `style`, `test` and `refactor` changes that are done across all
|
|
||||||
packages (e.g. `style: add missing semicolons`) and for docs changes that are not related to a
|
|
||||||
specific package (e.g. `docs: fix typo in tutorial`).
|
|
||||||
|
|
||||||
### Subject
|
* `changelog`: used for updating the release notes in CHANGELOG.md
|
||||||
The subject contains a succinct description of the change:
|
|
||||||
|
* `dev-infra`: used for dev-infra related changes within the directories /scripts, /tools and /dev-infra
|
||||||
|
|
||||||
|
* `docs-infra`: used for docs-app (angular.io) related changes within the /aio directory of the repo
|
||||||
|
|
||||||
|
* `migrations`: used for changes to the `ng update` migrations.
|
||||||
|
|
||||||
|
* `ngcc`: used for changes to the [Angular Compatibility Compiler](./packages/compiler-cli/ngcc/README.md)
|
||||||
|
|
||||||
|
* `ve`: used for changes specific to ViewEngine (legacy compiler/renderer).
|
||||||
|
|
||||||
|
* none/empty string: useful for `style`, `test` and `refactor` changes that are done across all packages (e.g. `style: add missing semicolons`) and for docs changes that are not related to a specific package (e.g. `docs: fix typo in tutorial`).
|
||||||
|
|
||||||
|
|
||||||
|
##### Summary
|
||||||
|
|
||||||
|
Use the summary field to provide a succinct description of the change:
|
||||||
|
|
||||||
* use the imperative, present tense: "change" not "changed" nor "changes"
|
* use the imperative, present tense: "change" not "changed" nor "changes"
|
||||||
* don't capitalize the first letter
|
* don't capitalize the first letter
|
||||||
* no dot (.) at the end
|
* no dot (.) at the end
|
||||||
|
|
||||||
### Body
|
|
||||||
Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes".
|
|
||||||
The body should include the motivation for the change and contrast this with previous behavior.
|
|
||||||
|
|
||||||
### Footer
|
#### Commit Message Body
|
||||||
The footer should contain any information about **Breaking Changes** and is also the place to
|
|
||||||
reference GitHub issues that this commit **Closes**.
|
|
||||||
|
|
||||||
**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit message is then used for this.
|
Just as in the summary, use the imperative, present tense: "fix" not "fixed" nor "fixes".
|
||||||
|
|
||||||
|
Explain the motivation for the change in the commit message body. This commit message should explain _why_ you are making the change.
|
||||||
|
You can include a comparison of the previous behavior with the new behavior in order to illustrate the impact of the change.
|
||||||
|
|
||||||
|
|
||||||
|
#### Commit Message Footer
|
||||||
|
|
||||||
|
The footer can contain information about breaking changes and is also the place to reference GitHub issues, Jira tickets, and other PRs that this commit closes or is related to.
|
||||||
|
|
||||||
|
```
|
||||||
|
BREAKING CHANGE: <breaking change summary>
|
||||||
|
<BLANK LINE>
|
||||||
|
<breaking change description + migration instructions>
|
||||||
|
<BLANK LINE>
|
||||||
|
<BLANK LINE>
|
||||||
|
Fixes #<issue number>
|
||||||
|
```
|
||||||
|
|
||||||
|
Breaking Change section should start with the phrase "BREAKING CHANGE: " followed by a summary of the breaking change, a blank line, and a detailed description of the breaking change that also includes migration instructions.
|
||||||
|
|
||||||
|
|
||||||
|
### Revert commits
|
||||||
|
|
||||||
|
If the commit reverts a previous commit, it should begin with `revert: `, followed by the header of the reverted commit.
|
||||||
|
|
||||||
|
The content of the commit message body should contain:
|
||||||
|
|
||||||
|
- information about the SHA of the commit being reverted in the following format: `This reverts commit <SHA>`,
|
||||||
|
- a clear description of the reason for reverting the commit message.
|
||||||
|
|
||||||
A detailed explanation can be found in this [document][commit-message-format].
|
|
||||||
|
|
||||||
## <a name="cla"></a> Signing the CLA
|
## <a name="cla"></a> Signing the CLA
|
||||||
|
|
||||||
@ -271,18 +332,17 @@ changes to be accepted, the CLA must be signed. It's a quick process, we promise
|
|||||||
* For corporations, we'll need you to
|
* For corporations, we'll need you to
|
||||||
[print, sign and one of scan+email, fax or mail the form][corporate-cla].
|
[print, sign and one of scan+email, fax or mail the form][corporate-cla].
|
||||||
|
|
||||||
<hr>
|
If you have more than one GitHub accounts, or multiple email addresses associated with a single GitHub account, you must sign the CLA using the primary email address of the GitHub account used to author Git commits and send pull requests.
|
||||||
|
|
||||||
If you have more than one Git identity, you must make sure that you sign the CLA using the primary email address associated with the ID that has been granted access to the Angular repository. Git identities can be associated with more than one email address, and only one is primary. Here are some links to help you sort out multiple Git identities and email addresses:
|
The following documents can help you sort out issues with GitHub accounts and multiple email addresses:
|
||||||
|
|
||||||
* https://help.github.com/articles/setting-your-commit-email-address-in-git/
|
* https://help.github.com/articles/setting-your-commit-email-address-in-git/
|
||||||
* https://stackoverflow.com/questions/37245303/what-does-usera-committed-with-userb-13-days-ago-on-github-mean
|
* https://stackoverflow.com/questions/37245303/what-does-usera-committed-with-userb-13-days-ago-on-github-mean
|
||||||
* https://help.github.com/articles/about-commit-email-addresses/
|
* https://help.github.com/articles/about-commit-email-addresses/
|
||||||
* https://help.github.com/articles/blocking-command-line-pushes-that-expose-your-personal-email-address/
|
* https://help.github.com/articles/blocking-command-line-pushes-that-expose-your-personal-email-address/
|
||||||
|
|
||||||
Note that if you have more than one Git identity, it is important to verify that you are logged in with the same ID with which you signed the CLA, before you commit changes. If not, your PR will fail the CLA check.
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
|
|
||||||
[angular-group]: https://groups.google.com/forum/#!forum/angular
|
[angular-group]: https://groups.google.com/forum/#!forum/angular
|
||||||
[coc]: https://github.com/angular/code-of-conduct/blob/master/CODE_OF_CONDUCT.md
|
[coc]: https://github.com/angular/code-of-conduct/blob/master/CODE_OF_CONDUCT.md
|
||||||
|
@ -58,7 +58,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"styles": [
|
"styles": [
|
||||||
"src/styles.scss"
|
"src/styles/main.scss"
|
||||||
],
|
],
|
||||||
"scripts": [],
|
"scripts": [],
|
||||||
"budgets": [
|
"budgets": [
|
||||||
@ -158,7 +158,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"styles": [
|
"styles": [
|
||||||
"src/styles.scss"
|
"src/styles/main.scss"
|
||||||
],
|
],
|
||||||
"scripts": []
|
"scripts": []
|
||||||
}
|
}
|
||||||
@ -193,4 +193,4 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"defaultProject": "site"
|
"defaultProject": "site"
|
||||||
}
|
}
|
||||||
|
@ -32,15 +32,15 @@ export const slideInAnimation =
|
|||||||
// #enddocregion style-view
|
// #enddocregion style-view
|
||||||
// #docregion query
|
// #docregion query
|
||||||
query(':enter', [
|
query(':enter', [
|
||||||
style({ left: '-100%'})
|
style({ left: '-100%' })
|
||||||
]),
|
]),
|
||||||
query(':leave', animateChild()),
|
query(':leave', animateChild()),
|
||||||
group([
|
group([
|
||||||
query(':leave', [
|
query(':leave', [
|
||||||
animate('300ms ease-out', style({ left: '100%'}))
|
animate('300ms ease-out', style({ left: '100%' }))
|
||||||
]),
|
]),
|
||||||
query(':enter', [
|
query(':enter', [
|
||||||
animate('300ms ease-out', style({ left: '0%'}))
|
animate('300ms ease-out', style({ left: '0%' }))
|
||||||
])
|
])
|
||||||
]),
|
]),
|
||||||
query(':enter', animateChild()),
|
query(':enter', animateChild()),
|
||||||
@ -56,15 +56,15 @@ export const slideInAnimation =
|
|||||||
})
|
})
|
||||||
]),
|
]),
|
||||||
query(':enter', [
|
query(':enter', [
|
||||||
style({ left: '-100%'})
|
style({ left: '-100%' })
|
||||||
]),
|
]),
|
||||||
query(':leave', animateChild()),
|
query(':leave', animateChild()),
|
||||||
group([
|
group([
|
||||||
query(':leave', [
|
query(':leave', [
|
||||||
animate('200ms ease-out', style({ left: '100%'}))
|
animate('200ms ease-out', style({ left: '100%' }))
|
||||||
]),
|
]),
|
||||||
query(':enter', [
|
query(':enter', [
|
||||||
animate('300ms ease-out', style({ left: '0%'}))
|
animate('300ms ease-out', style({ left: '0%' }))
|
||||||
])
|
])
|
||||||
]),
|
]),
|
||||||
query(':enter', animateChild()),
|
query(':enter', animateChild()),
|
||||||
|
@ -17,7 +17,7 @@ Toggle All Animations <input type="checkbox" [checked]="!animationsDisabled" (cl
|
|||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<!-- #docregion route-animations-outlet -->
|
<!-- #docregion route-animations-outlet -->
|
||||||
<div [@routeAnimations]="prepareRoute(outlet)" >
|
<div [@routeAnimations]="prepareRoute(outlet)">
|
||||||
<router-outlet #outlet="outlet"></router-outlet>
|
<router-outlet #outlet="outlet"></router-outlet>
|
||||||
</div>
|
</div>
|
||||||
<!-- #enddocregion route-animations-outlet -->
|
<!-- #enddocregion route-animations-outlet -->
|
||||||
|
@ -76,15 +76,15 @@ export class ConfigService {
|
|||||||
console.error('An error occurred:', error.error.message);
|
console.error('An error occurred:', error.error.message);
|
||||||
} else {
|
} else {
|
||||||
// The backend returned an unsuccessful response code.
|
// The backend returned an unsuccessful response code.
|
||||||
// The response body may contain clues as to what went wrong,
|
// The response body may contain clues as to what went wrong.
|
||||||
console.error(
|
console.error(
|
||||||
`Backend returned code ${error.status}, ` +
|
`Backend returned code ${error.status}, ` +
|
||||||
`body was: ${error.error}`);
|
`body was: ${error.error}`);
|
||||||
}
|
}
|
||||||
// return an observable with a user-facing error message
|
// Return an observable with a user-facing error message.
|
||||||
return throwError(
|
return throwError(
|
||||||
'Something bad happened; please try again later.');
|
'Something bad happened; please try again later.');
|
||||||
};
|
}
|
||||||
// #enddocregion handleError
|
// #enddocregion handleError
|
||||||
|
|
||||||
makeIntentionalError() {
|
makeIntentionalError() {
|
||||||
|
12
aio/content/examples/i18n/stackblitz.json
Normal file
12
aio/content/examples/i18n/stackblitz.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"description": "i18n",
|
||||||
|
"files":[
|
||||||
|
"!**/*.d.ts",
|
||||||
|
"!**/*.js",
|
||||||
|
"!**/*.[0-9].*",
|
||||||
|
"!doc-files/**/*",
|
||||||
|
"**/*.xlf"
|
||||||
|
],
|
||||||
|
"file": "src/app/app.component.ts",
|
||||||
|
"tags": ["Angular", "i18n", "internationalization"]
|
||||||
|
}
|
@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"files": [
|
|
||||||
"!dist/",
|
|
||||||
"!**/*.d.ts",
|
|
||||||
"!src/**/*.js",
|
|
||||||
"!doc-files/**/*",
|
|
||||||
"**/*.xlf"
|
|
||||||
]
|
|
||||||
}
|
|
@ -6,5 +6,5 @@ import { Component } from '@angular/core';
|
|||||||
templateUrl: './app.component.html'
|
templateUrl: './app.component.html'
|
||||||
})
|
})
|
||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
birthday = new Date(1988, 3, 15); // April 15, 1988
|
birthday = new Date(1988, 3, 15); // April 15, 1988 -- since month parameter is zero-based
|
||||||
}
|
}
|
||||||
|
@ -8,5 +8,5 @@ import { Component } from '@angular/core';
|
|||||||
// #enddocregion hero-birthday-template
|
// #enddocregion hero-birthday-template
|
||||||
})
|
})
|
||||||
export class HeroBirthdayComponent {
|
export class HeroBirthdayComponent {
|
||||||
birthday = new Date(1988, 3, 15); // April 15, 1988
|
birthday = new Date(1988, 3, 15); // April 15, 1988 -- since month parameter is zero-based
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import { Component } from '@angular/core';
|
|||||||
})
|
})
|
||||||
// #docregion class
|
// #docregion class
|
||||||
export class HeroBirthday2Component {
|
export class HeroBirthday2Component {
|
||||||
birthday = new Date(1988, 3, 15); // April 15, 1988
|
birthday = new Date(1988, 3, 15); // April 15, 1988 -- since month parameter is zero-based
|
||||||
toggle = true; // start with true == shortDate
|
toggle = true; // start with true == shortDate
|
||||||
|
|
||||||
get format() { return this.toggle ? 'shortDate' : 'fullDate'; }
|
get format() { return this.toggle ? 'shortDate' : 'fullDate'; }
|
||||||
|
7
aio/content/examples/providers/src/app/user.service.2.ts
Normal file
7
aio/content/examples/providers/src/app/user.service.2.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'any',
|
||||||
|
})
|
||||||
|
export class UserService {
|
||||||
|
}
|
@ -6,13 +6,11 @@ import { Routes, RouterModule } from '@angular/router'; // CLI imports router
|
|||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{ path: 'first-component', component: FirstComponent },
|
{ path: 'first-component', component: FirstComponent },
|
||||||
{ path: 'second-component', component: SecondComponent },
|
{ path: 'second-component', component: SecondComponent },
|
||||||
// #enddocregion routes
|
// #enddocregion routes, routes-with-wildcard
|
||||||
{ path: '', redirectTo: '/first-component', pathMatch: 'full' }, // redirect to `first-component`
|
{ path: '', redirectTo: '/first-component', pathMatch: 'full' }, // redirect to `first-component`
|
||||||
{ path: '**', component: FirstComponent },
|
// #docregion routes-with-wildcard
|
||||||
// #enddocregion redirect
|
|
||||||
{ path: '**', component: PageNotFoundComponent }, // Wildcard route for a 404 page
|
{ path: '**', component: PageNotFoundComponent }, // Wildcard route for a 404 page
|
||||||
// #docregion routes
|
// #docregion routes
|
||||||
// #docregion redirect
|
|
||||||
];
|
];
|
||||||
// #enddocregion routes, routes-with-wildcard, redirect
|
// #enddocregion routes, routes-with-wildcard, redirect
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ export class HeroesComponent implements OnInit {
|
|||||||
|
|
||||||
onSelect(hero: Hero): void {
|
onSelect(hero: Hero): void {
|
||||||
this.selectedHero = hero;
|
this.selectedHero = hero;
|
||||||
this.messageService.add(`HeroService: Selected hero id=${hero.id}`);
|
this.messageService.add(`HeroesComponent: Selected hero id=${hero.id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #docregion getHeroes
|
// #docregion getHeroes
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Angular compiler options
|
# Angular compiler options
|
||||||
|
|
||||||
When you use [AOT compilation](guide/aot-compiler), you can control how your application is compiled by specifying *template* compiler options in the `tsconfig.json` [TypeScript configuration file](guide/typescript-configuration).
|
When you use [AOT compilation](guide/aot-compiler), you can control how your application is compiled by specifying *template* compiler options in the [TypeScript configuration file](guide/typescript-configuration).
|
||||||
|
|
||||||
The template options object, `angularCompilerOptions`, is a sibling to the `compilerOptions` object that supplies standard options to the TypeScript compiler.
|
The template options object, `angularCompilerOptions`, is a sibling to the `compilerOptions` object that supplies standard options to the TypeScript compiler.
|
||||||
|
|
||||||
@ -21,11 +21,11 @@ The template options object, `angularCompilerOptions`, is a sibling to the `comp
|
|||||||
{@a tsconfig-extends}
|
{@a tsconfig-extends}
|
||||||
## Configuration inheritance with extends
|
## Configuration inheritance with extends
|
||||||
|
|
||||||
Like the TypeScript compiler, The Angular AOT compiler also supports `extends` in the `angularCompilerOptions` section of the TypeScript configuration file, `tsconfig.json`.
|
Like the TypeScript compiler, The Angular AOT compiler also supports `extends` in the `angularCompilerOptions` section of the TypeScript configuration file.
|
||||||
The `extends` property is at the top level, parallel to `compilerOptions` and `angularCompilerOptions`.
|
The `extends` property is at the top level, parallel to `compilerOptions` and `angularCompilerOptions`.
|
||||||
|
|
||||||
A TypeScript configuration can inherit settings from another file using the `extends` property.
|
A TypeScript configuration can inherit settings from another file using the `extends` property.
|
||||||
The configuration options from the base file are loaded first, then overridden by those in the inheriting `tsconfig` file.
|
The configuration options from the base file are loaded first, then overridden by those in the inheriting configuration file.
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ For help in understanding and resolving these problems, see [AOT Metadata Errors
|
|||||||
|
|
||||||
### Configuring AOT compilation
|
### Configuring AOT compilation
|
||||||
|
|
||||||
You can provide options in the `tsconfig.json` [TypeScript configuration file](guide/typescript-configuration) that control the compilation process. See [Angular compiler options](guide/angular-compiler-options) for a complete list of available options.
|
You can provide options in the [TypeScript configuration file](guide/typescript-configuration) that controls the compilation process. See [Angular compiler options](guide/angular-compiler-options) for a complete list of available options.
|
||||||
|
|
||||||
## Phase 1: Code analysis
|
## Phase 1: Code analysis
|
||||||
|
|
||||||
@ -211,7 +211,7 @@ The compiler later reports the error if it needs that piece of metadata to gener
|
|||||||
|
|
||||||
<div class="alert is-helpful">
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
If you want `ngc` to report syntax errors immediately rather than produce a `.metadata.json` file with errors, set the `strictMetadataEmit` option in the TypeScript configuration file, `tsconfig.json`.
|
If you want `ngc` to report syntax errors immediately rather than produce a `.metadata.json` file with errors, set the `strictMetadataEmit` option in the TypeScript configuration file.
|
||||||
|
|
||||||
```
|
```
|
||||||
"angularCompilerOptions": {
|
"angularCompilerOptions": {
|
||||||
@ -548,7 +548,7 @@ It does not, however, rewrite the `.d.ts` file, so TypeScript doesn't recognize
|
|||||||
One of the Angular compiler's most helpful features is the ability to type-check expressions within templates, and catch any errors before they cause crashes at runtime.
|
One of the Angular compiler's most helpful features is the ability to type-check expressions within templates, and catch any errors before they cause crashes at runtime.
|
||||||
In the template type-checking phase, the Angular template compiler uses the TypeScript compiler to validate the binding expressions in templates.
|
In the template type-checking phase, the Angular template compiler uses the TypeScript compiler to validate the binding expressions in templates.
|
||||||
|
|
||||||
Enable this phase explicitly by adding the compiler option `"fullTemplateTypeCheck"` in the `"angularCompilerOptions"` of the project's `tsconfig.json`
|
Enable this phase explicitly by adding the compiler option `"fullTemplateTypeCheck"` in the `"angularCompilerOptions"` of the project's TypeScript configuration file
|
||||||
(see [Angular Compiler Options](guide/angular-compiler-options)).
|
(see [Angular Compiler Options](guide/angular-compiler-options)).
|
||||||
|
|
||||||
<div class="alert is-helpful">
|
<div class="alert is-helpful">
|
||||||
|
@ -11,7 +11,7 @@ The basic building blocks are *NgModules*, which provide a compilation context f
|
|||||||
|
|
||||||
* Components use *services*, which provide specific functionality not directly related to views. Service providers can be *injected* into components as *dependencies*, making your code modular, reusable, and efficient.
|
* Components use *services*, which provide specific functionality not directly related to views. Service providers can be *injected* into components as *dependencies*, making your code modular, reusable, and efficient.
|
||||||
|
|
||||||
Both components and services are simply classes, with *decorators* that mark their type and provide metadata that tells Angular how to use them.
|
Modules, components and services are classes that use *decorators*. These decorators mark their type and provide metadata that tells Angular how to use them.
|
||||||
|
|
||||||
* The metadata for a component class associates it with a *template* that defines a view. A template combines ordinary HTML with Angular *directives* and *binding markup* that allow Angular to modify the HTML before rendering it for display.
|
* The metadata for a component class associates it with a *template* that defines a view. A template combines ordinary HTML with Angular *directives* and *binding markup* that allow Angular to modify the HTML before rendering it for display.
|
||||||
|
|
||||||
|
@ -262,6 +262,33 @@ Each budget entry is a JSON object with the following properties:
|
|||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
{@a commonjs }
|
||||||
|
## Configuring CommonJS dependencies
|
||||||
|
|
||||||
|
<div class="alert is-important">
|
||||||
|
|
||||||
|
It is recommended that you avoid depending on CommonJS modules in your Angular applications.
|
||||||
|
Depending on CommonJS modules can prevent bundlers and minifiers from optimizing your application, which results in larger bundle sizes.
|
||||||
|
Instead, it is recommended that you use [ECMAScript modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) in your entire application.
|
||||||
|
For more information, see [How CommonJS is making your bundles larger](https://web.dev/commonjs-larger-bundles/).
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
The Angular CLI outputs warnings if it detects that your browser application depends on CommonJS modules.
|
||||||
|
To disable these warnings, you can add the CommonJS module name to `allowedCommonJsDependencies` option in the `build` options located in `angular.json` file.
|
||||||
|
|
||||||
|
<code-example lang="json">
|
||||||
|
"build": {
|
||||||
|
"builder": "@angular-devkit/build-angular:browser",
|
||||||
|
"options": {
|
||||||
|
"allowedCommonJsDependencies": [
|
||||||
|
"lodash"
|
||||||
|
]
|
||||||
|
...
|
||||||
|
}
|
||||||
|
...
|
||||||
|
},
|
||||||
|
</code-example>
|
||||||
|
|
||||||
{@a browser-compat}
|
{@a browser-compat}
|
||||||
|
|
||||||
|
@ -197,11 +197,11 @@ Like `EvenBetterLogger`, `HeroService` needs to know if the user is authorized
|
|||||||
That authorization can change during the course of a single application session,
|
That authorization can change during the course of a single application session,
|
||||||
as when you log in a different user.
|
as when you log in a different user.
|
||||||
|
|
||||||
Let's say you don't want to inject `UserService` directly into `HeroService`, because you don't want to complicate that service with security-sensitive information.
|
Imagine that you don't want to inject `UserService` directly into `HeroService`, because you don't want to complicate that service with security-sensitive information.
|
||||||
`HeroService` won't have direct access to the user information to decide
|
`HeroService` won't have direct access to the user information to decide
|
||||||
who is authorized and who isn't.
|
who is authorized and who isn't.
|
||||||
|
|
||||||
To resolve this, we give the `HeroService` constructor a boolean flag to control display of secret heroes.
|
To resolve this, give the `HeroService` constructor a boolean flag to control display of secret heroes.
|
||||||
|
|
||||||
<code-example path="dependency-injection/src/app/heroes/hero.service.ts" region="internals" header="src/app/heroes/hero.service.ts (excerpt)"></code-example>
|
<code-example path="dependency-injection/src/app/heroes/hero.service.ts" region="internals" header="src/app/heroes/hero.service.ts (excerpt)"></code-example>
|
||||||
|
|
||||||
|
@ -320,7 +320,7 @@ You can dramatically reduce launch time by only loading the application modules
|
|||||||
absolutely must be present when the app starts.
|
absolutely must be present when the app starts.
|
||||||
|
|
||||||
Configure the Angular Router to defer loading of all other modules (and their associated code), either by
|
Configure the Angular Router to defer loading of all other modules (and their associated code), either by
|
||||||
[waiting until the app has launched](guide/router#preloading "Preloading")
|
[waiting until the app has launched](guide/router-tutorial-toh#preloading "Preloading")
|
||||||
or by [_lazy loading_](guide/router#lazy-loading "Lazy loading")
|
or by [_lazy loading_](guide/router#lazy-loading "Lazy loading")
|
||||||
them on demand.
|
them on demand.
|
||||||
|
|
||||||
@ -469,7 +469,7 @@ The following configurations determine your requirements.
|
|||||||
|
|
||||||
* TypeScript configuration
|
* TypeScript configuration
|
||||||
|
|
||||||
In the TypeScript configuration file, `tsconfig.json`, the "target" option in the `compilerOptions` section determines the ECMAScript target version that the code is compiled to.
|
In the TypeScript configuration file, the "target" option in the `compilerOptions` section determines the ECMAScript target version that the code is compiled to.
|
||||||
Modern browsers support ES2015 natively, while ES5 is more commonly used to support legacy browsers.
|
Modern browsers support ES2015 natively, while ES5 is more commonly used to support legacy browsers.
|
||||||
|
|
||||||
<div class="alert is-helpful">
|
<div class="alert is-helpful">
|
||||||
|
@ -490,6 +490,56 @@ If you rely on the behavior that the same object instance should cause change de
|
|||||||
- Clone the resulting value so that it has a new identity.
|
- Clone the resulting value so that it has a new identity.
|
||||||
- Explicitly call [`ChangeDetectorRef.detectChanges()`](api/core/ChangeDetectorRef#detectchanges) to force the update.
|
- Explicitly call [`ChangeDetectorRef.detectChanges()`](api/core/ChangeDetectorRef#detectchanges) to force the update.
|
||||||
|
|
||||||
|
{@a deprecated-cli-flags}
|
||||||
|
## Deprecated CLI APIs and Options
|
||||||
|
|
||||||
|
This section contains a complete list all of the currently deprecated CLI flags.
|
||||||
|
|
||||||
|
### @angular-devkit/build-angular
|
||||||
|
|
||||||
|
| API/Option | May be removed in | Notes |
|
||||||
|
| ------------------------------- | ----------------- |-------------------------------------------------------------------------------- |
|
||||||
|
| `i18nFile` | <!--v9--> v11 | Specified in the project locale configuration in version 9 and later. |
|
||||||
|
| `i18nFormat` | <!--v9--> v11 | Format is now automatically detected. |
|
||||||
|
| `i18nLocale` | <!--v9--> v11 | New [localization option](/guide/i18n#localize-config) in version 9 and later. |
|
||||||
|
| `lazyModules` | <!--v9--> v11 | Used with deprecated SystemJsNgModuleLoader. |
|
||||||
|
| `rebaseRootRelativeCssUrls` | <!--v8--> v11 | Intended only to assist with specific migration issues. |
|
||||||
|
| `scripts[].lazy` | <!--v8--> v11 | Renamed to `scripts[].inject`. |
|
||||||
|
| `styles[].lazy` | <!--v8--> v11 | Renamed to `styles[].inject`. |
|
||||||
|
| `i18nFormat` | <!--v9--> v11 | Renamed to `format` to simplify the user experience. |
|
||||||
|
| `i18nLocale` | <!--v9--> v11 | Redundant with project’s source locale. |
|
||||||
|
| `scripts[].lazy` | <!--v8--> v11 | Renamed to `scripts[].inject`. |
|
||||||
|
| `styles[].lazy` | <!--v8--> v11 | Renamed to `styles[].inject`. |
|
||||||
|
| `i18nFile` | <!--v9--> v11 | Specified in the project locale configuration in version 9 and later. |
|
||||||
|
| `i18nFormat` | <!--v9--> v11 | Format is now automatically detected. |
|
||||||
|
| `i18nLocale` | <!--v9--> v11 | New [localization option](/guide/i18n#localize-config) in version 9 and later. |
|
||||||
|
| `lazyModules` | <!--v9--> v11 | Used with deprecated SystemJsNgModuleLoader. |
|
||||||
|
|
||||||
|
### @angular-devkit/core
|
||||||
|
|
||||||
|
| API/Option | May be removed in | Notes |
|
||||||
|
| ------------------------------- | ----------------- |-------------------------------------------------------------------------------- |
|
||||||
|
| `ModuleNotFoundException` | <!--v8--> v10 | Not used within projects. Used with Tooling API only. Not Yarn PnP compatible and not used in the Angular CLI. Use Node.js [require.resolve](https://nodejs.org/api/modules.html#modules_require_resolve_request_options).|
|
||||||
|
| `resolve` | <!--v8--> v10 | Not used within projects. Used with Tooling API only. Not Yarn PnP compatible and not used in the Angular CLI. Use Node.js [require.resolve](https://nodejs.org/api/modules.html#modules_require_resolve_request_options).|
|
||||||
|
| `setResolveHook` | <!--v8--> v10 | Not used within projects. Used with Tooling API only. Not Yarn PnP compatible and not used in the Angular CLI. Use Node.js [require.resolve](https://nodejs.org/api/modules.html#modules_require_resolve_request_options).|
|
||||||
|
| `ResolveOptions` | <!--v8--> v10 | Not used within projects. Used with Tooling API only. Not Yarn PnP compatible and not used in the Angular CLI. Use Node.js [require.resolve](https://nodejs.org/api/modules.html#modules_require_resolve_request_options).|
|
||||||
|
| `terminal` | <!--v8--> v10 | Unused implementation of terminal codes (color). |
|
||||||
|
| `isObservable` | <!--v8--> v10 | Not used within projects. Used with Tooling API only. Use `isObservable` function from the `rxjs` package.|
|
||||||
|
|
||||||
|
### @ngtools/webpack
|
||||||
|
|
||||||
|
| API/Option | May be removed in | Notes |
|
||||||
|
| ------------------------------- | ----------------- |-------------------------------------------------------------------------------- |
|
||||||
|
| `discoverLazyRoutes` | <!--v9--> TBD | Used with deprecated SystemJsNgModuleLoader. |
|
||||||
|
| `additionalLazyModules` | <!--v9--> TBD | Used with deprecated SystemJsNgModuleLoader. |
|
||||||
|
| `additionalLazyModuleResources` | <!--v9--> TBD | Used with deprecated SystemJsNgModuleLoader. |
|
||||||
|
|
||||||
|
### @schematics/angular
|
||||||
|
|
||||||
|
| API/Option | May be removed in | Notes |
|
||||||
|
| ------------------------------- | ----------------- |-------------------------------------------------------------------------------- |
|
||||||
|
| `entryComponent` | <!--v9--> TBD | No longer needed with Ivy. |
|
||||||
|
|
||||||
{@a removed}
|
{@a removed}
|
||||||
## Removed APIs
|
## Removed APIs
|
||||||
|
|
||||||
|
@ -117,9 +117,9 @@ The recently-developed [custom elements](https://developer.mozilla.org/en-US/doc
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
In browsers that support Custom Elements natively, the specification requires developers use ES2015 classes to define Custom Elements - developers can opt-in to this by setting the `target: "es2015"` property in their project's `tsconfig.json`. As Custom Element and ES2015 support may not be available in all browsers, developers can instead choose to use a polyfill to support older browsers and ES5 code.
|
In browsers that support Custom Elements natively, the specification requires developers use ES2015 classes to define Custom Elements - developers can opt-in to this by setting the `target: "es2015"` property in their project's [TypeScript configuration file](/guide/typescript-configuration). As Custom Element and ES2015 support may not be available in all browsers, developers can instead choose to use a polyfill to support older browsers and ES5 code.
|
||||||
|
|
||||||
Use the [Angular CLI](cli) to automatically set up your project with the correct polyfill: `ng add @angular/elements --name=*your_project_name*`.
|
Use the [Angular CLI](cli) to automatically set up your project with the correct polyfill: `ng add @angular/elements --project=*your_project_name*`.
|
||||||
- For more information about polyfills, see [polyfill documentation](https://www.webcomponents.org/polyfills).
|
- For more information about polyfills, see [polyfill documentation](https://www.webcomponents.org/polyfills).
|
||||||
|
|
||||||
- For more information about Angular browser support, see [Browser Support](guide/browser-support).
|
- For more information about Angular browser support, see [Browser Support](guide/browser-support).
|
||||||
@ -186,7 +186,7 @@ aDialog.content = 123; // <-- ERROR: TypeScript knows this should be a string.
|
|||||||
aDialog.body = 'News'; // <-- ERROR: TypeScript knows there is no `body` property on `aDialog`.
|
aDialog.body = 'News'; // <-- ERROR: TypeScript knows there is no `body` property on `aDialog`.
|
||||||
```
|
```
|
||||||
|
|
||||||
This is a good way to quickly get TypeScript features, such as type checking and autocomplete support, for you custom element. But it can get cumbersome if you need it in several places, because you have to cast the return type on every occurrence.
|
This is a good way to quickly get TypeScript features, such as type checking and autocomplete support, for your custom element. But it can get cumbersome if you need it in several places, because you have to cast the return type on every occurrence.
|
||||||
|
|
||||||
An alternative way, that only requires defining each custom element's type once, is augmenting the `HTMLElementTagNameMap`, which TypeScript uses to infer the type of a returned element based on its tag name (for DOM methods such as `document.createElement()`, `document.querySelector()`, etc.):
|
An alternative way, that only requires defining each custom element's type once, is augmenting the `HTMLElementTagNameMap`, which TypeScript uses to infer the type of a returned element based on its tag name (for DOM methods such as `document.createElement()`, `document.querySelector()`, etc.):
|
||||||
|
|
||||||
|
@ -40,7 +40,8 @@ The top level of the workspace contains workspace-wide configuration files, conf
|
|||||||
| `package-lock.json` | Provides version information for all packages installed into `node_modules` by the npm client. See [npm documentation](https://docs.npmjs.com/files/package-lock.json) for details. If you use the yarn client, this file will be [yarn.lock](https://yarnpkg.com/lang/en/docs/yarn-lock/) instead. |
|
| `package-lock.json` | Provides version information for all packages installed into `node_modules` by the npm client. See [npm documentation](https://docs.npmjs.com/files/package-lock.json) for details. If you use the yarn client, this file will be [yarn.lock](https://yarnpkg.com/lang/en/docs/yarn-lock/) instead. |
|
||||||
| `src/` | Source files for the root-level application project. |
|
| `src/` | Source files for the root-level application project. |
|
||||||
| `node_modules/` | Provides [npm packages](guide/npm-packages) to the entire workspace. Workspace-wide `node_modules` dependencies are visible to all projects. |
|
| `node_modules/` | Provides [npm packages](guide/npm-packages) to the entire workspace. Workspace-wide `node_modules` dependencies are visible to all projects. |
|
||||||
| `tsconfig.json` | Default [TypeScript](https://www.typescriptlang.org/) configuration for projects in the workspace. |
|
| `tsconfig.json` | The `tsconfig.json` file is a ["Solution Style"](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#support-for-solution-style-tsconfigjson-files) TypeScript configuration file. Code editors and TypeScript’s language server use this file to improve development experience. Compilers do not use this file. |
|
||||||
|
| `tsconfig.base.json` | The base [TypeScript](https://www.typescriptlang.org/) configuration for projects in the workspace. All other configuration files inherit from this base file. For more information, see the [Configuration inheritance with extends](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#configuration-inheritance-with-extends) section of the TypeScript documentation.|
|
||||||
| `tslint.json` | Default [TSLint](https://palantir.github.io/tslint/) configuration for projects in the workspace. |
|
| `tslint.json` | Default [TSLint](https://palantir.github.io/tslint/) configuration for projects in the workspace. |
|
||||||
|
|
||||||
|
|
||||||
@ -77,6 +78,12 @@ Files at the top level of `src/` support testing and running your application. S
|
|||||||
| `styles.sass` | Lists CSS files that supply styles for a project. The extension reflects the style preprocessor you have configured for the project. |
|
| `styles.sass` | Lists CSS files that supply styles for a project. The extension reflects the style preprocessor you have configured for the project. |
|
||||||
| `test.ts` | The main entry point for your unit tests, with some Angular-specific configuration. You don't typically need to edit this file. |
|
| `test.ts` | The main entry point for your unit tests, with some Angular-specific configuration. You don't typically need to edit this file. |
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
If you create an application using Angular's strict mode, you will also have an additional `package.json` file in the `src/app` directory. For more information, see [Strict mode](/guide/strict-mode).
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
{@a app-src}
|
{@a app-src}
|
||||||
|
|
||||||
Inside the `src/` folder, the `app/` folder contains your project's logic and data.
|
Inside the `src/` folder, the `app/` folder contains your project's logic and data.
|
||||||
@ -89,13 +96,14 @@ Angular components, templates, and styles go here.
|
|||||||
| `app/app.component.css` | Defines the base CSS stylesheet for the root `AppComponent`. |
|
| `app/app.component.css` | Defines the base CSS stylesheet for the root `AppComponent`. |
|
||||||
| `app/app.component.spec.ts` | Defines a unit test for the root `AppComponent`. |
|
| `app/app.component.spec.ts` | Defines a unit test for the root `AppComponent`. |
|
||||||
| `app/app.module.ts` | Defines the root module, named `AppModule`, that tells Angular how to assemble the application. Initially declares only the `AppComponent`. As you add more components to the app, they must be declared here. |
|
| `app/app.module.ts` | Defines the root module, named `AppModule`, that tells Angular how to assemble the application. Initially declares only the `AppComponent`. As you add more components to the app, they must be declared here. |
|
||||||
|
| `app/package.json` | This file is generated only in applications created using `--strict` mode. This file is not used by package managers. It is used to tell the tools and bundlers whether the code under this directory is free of non-local [side-effects](guide/strict-mode#side-effect). |
|
||||||
|
|
||||||
### Application configuration files
|
### Application configuration files
|
||||||
|
|
||||||
The application-specific configuration files for the root application reside at the workspace root level.
|
The application-specific configuration files for the root application reside at the workspace root level.
|
||||||
For a multi-project workspace, project-specific configuration files are in the project root, under `projects/project-name/`.
|
For a multi-project workspace, project-specific configuration files are in the project root, under `projects/project-name/`.
|
||||||
|
|
||||||
Project-specific [TypeScript](https://www.typescriptlang.org/) configuration files inherit from the workspace-wide `tsconfig.json`, and project-specific [TSLint](https://palantir.github.io/tslint/) configuration files inherit from the workspace-wide `tslint.json`.
|
Project-specific [TypeScript](https://www.typescriptlang.org/) configuration files inherit from the workspace-wide `tsconfig.base.json`, and project-specific [TSLint](https://palantir.github.io/tslint/) configuration files inherit from the workspace-wide `tslint.json`.
|
||||||
|
|
||||||
| APPLICATION-SPECIFIC CONFIG FILES | PURPOSE |
|
| APPLICATION-SPECIFIC CONFIG FILES | PURPOSE |
|
||||||
| :--------------------- | :------------------------------------------|
|
| :--------------------- | :------------------------------------------|
|
||||||
|
@ -117,7 +117,7 @@ As users change values and make selections through the view, the new values must
|
|||||||
Similarly, when the program logic changes values in the data model, those values must be reflected in the view.
|
Similarly, when the program logic changes values in the data model, those values must be reflected in the view.
|
||||||
|
|
||||||
Reactive and template-driven forms differ in how they handle data flowing from the user or from programmatic changes.
|
Reactive and template-driven forms differ in how they handle data flowing from the user or from programmatic changes.
|
||||||
The following diagrams illustrate both kinds of data flow for each type of form, using the a favorite-color input field defined above.
|
The following diagrams illustrate both kinds of data flow for each type of form, using the favorite-color input field defined above.
|
||||||
|
|
||||||
### Data flow in reactive forms
|
### Data flow in reactive forms
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ In the course of this tutorial, you bind a sample form to data and handle user i
|
|||||||
* Add custom CSS to provide visual feedback on the status.
|
* Add custom CSS to provide visual feedback on the status.
|
||||||
* Show and hide validation-error messages.
|
* Show and hide validation-error messages.
|
||||||
4. Respond to a native HTML button-click event by adding to the model data.
|
4. Respond to a native HTML button-click event by adding to the model data.
|
||||||
5. Handle form submission using the [`ngSubmit`(api/forms/NgForm#properties)] output property of the form.
|
5. Handle form submission using the [`ngSubmit`](api/forms/NgForm#properties) output property of the form.
|
||||||
* Disable the **Submit** button until the form is valid.
|
* Disable the **Submit** button until the form is valid.
|
||||||
* After submit, swap out the finished form for different content on the page.
|
* After submit, swap out the finished form for different content on the page.
|
||||||
|
|
||||||
@ -467,7 +467,7 @@ You will bind the form property that indicates its overall validity to the **Sub
|
|||||||
3. Run the application now. Notice that the button is enabled—although
|
3. Run the application now. Notice that the button is enabled—although
|
||||||
it doesn't do anything useful yet.
|
it doesn't do anything useful yet.
|
||||||
|
|
||||||
4. Delete the **Name** value. This violates the "required" rule, so it displays the error message&emdash;and notice that it also disables the **Submit** button.
|
4. Delete the **Name** value. This violates the "required" rule, so it displays the error message—and notice that it also disables the **Submit** button.
|
||||||
|
|
||||||
|
|
||||||
You didn't have to explicitly wire the button's enabled state to the form's validity.
|
You didn't have to explicitly wire the button's enabled state to the form's validity.
|
||||||
|
@ -732,7 +732,7 @@ The alternative is a [template-driven form](#template-driven-forms).
|
|||||||
When using reactive forms:
|
When using reactive forms:
|
||||||
|
|
||||||
* The "source of truth", the form model, is defined in the component class.
|
* The "source of truth", the form model, is defined in the component class.
|
||||||
* Validation is set up through validation functions rather than valdation directives.
|
* Validation is set up through validation functions rather than validation directives.
|
||||||
* Each control is explicitly created in the component class by creating a `FormControl` instance manually or with `FormBuilder`.
|
* Each control is explicitly created in the component class by creating a `FormControl` instance manually or with `FormBuilder`.
|
||||||
* The template input elements do *not* use `ngModel`.
|
* The template input elements do *not* use `ngModel`.
|
||||||
* The associated Angular directives are prefixed with `form`, such as `formControl`, `formGroup`, and `formControlName`.
|
* The associated Angular directives are prefixed with `form`, such as `formControl`, `formGroup`, and `formControlName`.
|
||||||
@ -950,6 +950,10 @@ Many code editors and IDEs support TypeScript either natively or with plug-ins.
|
|||||||
TypeScript is the preferred language for Angular development.
|
TypeScript is the preferred language for Angular development.
|
||||||
Read more about TypeScript at [typescriptlang.org](http://www.typescriptlang.org/).
|
Read more about TypeScript at [typescriptlang.org](http://www.typescriptlang.org/).
|
||||||
|
|
||||||
|
## TypeScript configuration file
|
||||||
|
|
||||||
|
A file specifies the root files and the compiler options required to compile a TypeScript project. For more information, see [TypeScript configuration](/guide/typescript-configuration).
|
||||||
|
|
||||||
|
|
||||||
{@a U}
|
{@a U}
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ searchHeroes(term: string): Observable {
|
|||||||
return this.http.jsonp(heroesUrl, 'callback').pipe(
|
return this.http.jsonp(heroesUrl, 'callback').pipe(
|
||||||
catchError(this.handleError('searchHeroes', [])) // then handle the error
|
catchError(this.handleError('searchHeroes', [])) // then handle the error
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
This request passes the `heroesURL` as the first parameter and the callback function name as the second parameter.
|
This request passes the `heroesURL` as the first parameter and the callback function name as the second parameter.
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -2,20 +2,20 @@
|
|||||||
|
|
||||||
The Angular team has worked hard to ensure Ivy is as backwards-compatible with the previous rendering engine ("View Engine") as possible.
|
The Angular team has worked hard to ensure Ivy is as backwards-compatible with the previous rendering engine ("View Engine") as possible.
|
||||||
However, in rare cases, minor changes were necessary to ensure that the Angular's behavior was predictable and consistent, correcting issues in the View Engine implementation.
|
However, in rare cases, minor changes were necessary to ensure that the Angular's behavior was predictable and consistent, correcting issues in the View Engine implementation.
|
||||||
In order to smooth the transition, we have provided [automated migrations](guide/updating-to-version-9#migrations) wherever possible so your application and library code is migrated automatically by the CLI.
|
In order to smooth the transition, we have provided [automated migrations](guide/updating-to-version-10#migrations) wherever possible so your application and library code is migrated automatically by the CLI.
|
||||||
That said, some applications will likely need to apply some manual updates.
|
That said, some applications will likely need to apply some manual updates.
|
||||||
|
|
||||||
{@a debugging}
|
{@a debugging}
|
||||||
## How to debug errors with Ivy
|
## How to debug errors with Ivy
|
||||||
|
|
||||||
In version 9, [a few deprecated APIs have been removed](guide/updating-to-version-9#removals) and there are a [few breaking changes](guide/updating-to-version-9#breaking-changes) unrelated to Ivy.
|
In version 10, [a few deprecated APIs have been removed](guide/updating-to-version-10#removals) and there are a [few breaking changes](guide/updating-to-version-10#breaking-changes) unrelated to Ivy.
|
||||||
If you're seeing errors after updating to version 9, you'll first want to rule those changes out.
|
If you're seeing errors after updating to version 9, you'll first want to rule those changes out.
|
||||||
|
|
||||||
To do so, temporarily [turn off Ivy](guide/ivy#opting-out-of-angular-ivy) in your `tsconfig.json` and re-start your app.
|
To do so, temporarily [turn off Ivy](guide/ivy#opting-out-of-angular-ivy) in your `tsconfig.base.json` and re-start your app.
|
||||||
|
|
||||||
If you're still seeing the errors, they are not specific to Ivy. In this case, you may want to consult the [general version 9 guide](guide/updating-to-version-9). If you've opted into any of the stricter type-checking settings that are new with v9, you may also want to check out the [template type-checking guide](guide/template-typecheck).
|
If you're still seeing the errors, they are not specific to Ivy. In this case, you may want to consult the [general version 10 guide](guide/updating-to-version-10). If you've opted into any of the new, stricter type-checking settings, you may also want to check out the [template type-checking guide](guide/template-typecheck).
|
||||||
|
|
||||||
If the errors are gone, switch back to Ivy by removing the changes to the `tsconfig.json` and review the list of expected changes below.
|
If the errors are gone, switch back to Ivy by removing the changes to the `tsconfig.base.json` and review the list of expected changes below.
|
||||||
|
|
||||||
{@a payload-size-debugging}
|
{@a payload-size-debugging}
|
||||||
### Payload size debugging
|
### Payload size debugging
|
||||||
|
@ -311,7 +311,7 @@ ngOnInit() {
|
|||||||
}
|
}
|
||||||
</code-example>
|
</code-example>
|
||||||
|
|
||||||
For more information with a working example, see the [routing tutorial section on preloading](guide/router#preloading-background-loading-of-feature-areas).
|
For more information with a working example, see the [routing tutorial section on preloading](guide/router-tutorial-toh#preloading-background-loading-of-feature-areas).
|
||||||
|
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
@ -495,7 +495,7 @@ for one turn of the browser's JavaScript cycle, which triggers a new change-dete
|
|||||||
|
|
||||||
#### Write lean hook methods to avoid performance problems
|
#### Write lean hook methods to avoid performance problems
|
||||||
|
|
||||||
When you run the *AfterView* sample, notice how frequently Angular calls `AfterViewChecked()`$emdash;often when there are no changes of interest.
|
When you run the *AfterView* sample, notice how frequently Angular calls `AfterViewChecked()`-often when there are no changes of interest.
|
||||||
Be very careful about how much logic or computation you put into one of these methods.
|
Be very careful about how much logic or computation you put into one of these methods.
|
||||||
|
|
||||||
<div class="lightbox">
|
<div class="lightbox">
|
||||||
|
55
aio/content/guide/migration-solution-style-tsconfig.md
Normal file
55
aio/content/guide/migration-solution-style-tsconfig.md
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
# Solution-style `tsconfig.json` migration
|
||||||
|
|
||||||
|
## What does this migration do?
|
||||||
|
|
||||||
|
This migration adds support to existing projects for TypeScript's new ["solution-style" tsconfig feature](https://devblogs.microsoft.com/typescript/announcing-typescript-3-9/#solution-style-tsconfig).
|
||||||
|
|
||||||
|
Support is added by making two changes:
|
||||||
|
|
||||||
|
1. Renaming the workspace-level `tsconfig.json` to `tsconfig.base.json`.
|
||||||
|
All project [TypeScript configuration files](guide/typescript-configuration) will extend from this base which contains the common options used throughout the workspace.
|
||||||
|
|
||||||
|
2. Adding the solution `tsconfig.json` file at the root of the workspace.
|
||||||
|
This `tsconfig.json` file will only contain references to project-level TypeScript configuration files and is only used by editors/IDEs.
|
||||||
|
|
||||||
|
As an example, the solution `tsconfig.json` for a new project is as follows:
|
||||||
|
```json
|
||||||
|
// This is a "Solution Style" tsconfig.json file, and is used by editors and TypeScript’s language server to improve development experience.
|
||||||
|
// It is not intended to be used to perform a compilation.
|
||||||
|
{
|
||||||
|
"files": [],
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"path": "./tsconfig.app.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./tsconfig.spec.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./e2e/tsconfig.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Why is this migration necessary?
|
||||||
|
|
||||||
|
Solution-style `tsconfig.json` files provide an improved editing experience and fix several long-standing defects when editing files in an IDE.
|
||||||
|
IDEs that leverage the TypeScript language service (for example, [Visual Studio Code](https://code.visualstudio.com)), will only use TypeScript configuration files that are named `tsconfig.json`.
|
||||||
|
In complex projects, there may be more than one compilation unit and each of these units may have different settings and options.
|
||||||
|
|
||||||
|
With the Angular CLI, a project will have application code that will target a browser.
|
||||||
|
It will also have unit tests that should not be included within the built application and that also need additional type information present (`jasmine` in this case).
|
||||||
|
Both parts of the project also share some but not all of the code within the project.
|
||||||
|
As a result, two separate TypeScript configuration files (`tsconfig.app.json` and `tsconfig.spec.json`) are needed to ensure that each part of the application is configured properly and that the right types are used for each part.
|
||||||
|
Also if web workers are used within a project, an additional tsconfig (`tsconfig.worker.json`) is needed.
|
||||||
|
Web workers use similar but incompatible types to the main browser application.
|
||||||
|
This requires the additional configuration file to ensure that the web worker files use the appropriate types and will build successfully.
|
||||||
|
|
||||||
|
While the Angular build system knows about all of these TypeScript configuration files, an IDE using TypeScript's language service does not.
|
||||||
|
Because of this, an IDE will not be able to properly analyze the code from each part of the project and may generate false errors or make suggestions that are incorrect for certain files.
|
||||||
|
By leveraging the new solution-style tsconfig, the IDE can now be aware of the configuration of each part of a project.
|
||||||
|
This allows each file to be treated appropriately based on its tsconfig.
|
||||||
|
IDE features such as error/warning reporting and auto-suggestion will operate more effectively as well.
|
||||||
|
|
||||||
|
The TypeScript 3.9 release [blog post](https://devblogs.microsoft.com/typescript/announcing-typescript-3-9/#solution-style-tsconfig) also contains some additional information regarding this new feature.
|
52
aio/content/guide/migration-update-libraries-tslib.md
Normal file
52
aio/content/guide/migration-update-libraries-tslib.md
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# `tslib` direct dependency migration
|
||||||
|
|
||||||
|
## What does this migration do?
|
||||||
|
|
||||||
|
If you have any libraries within your workspace, this migration will convert `tslib` peer dependencies to direct dependencies for the libraries.
|
||||||
|
TypeScript uses the `tslib` package to provide common helper functions used in compiled TypeScript code.
|
||||||
|
The `tslib` version is also updated to `2.0.0` to support TypeScript 3.9.
|
||||||
|
|
||||||
|
Before:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"name": "my-lib",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"peerDependencies": {
|
||||||
|
"@angular/common": "^9.0.0",
|
||||||
|
"@angular/core": "^9.0.0",
|
||||||
|
"tslib": "^1.12.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
After:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"name": "my-lib",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"peerDependencies": {
|
||||||
|
"@angular/common": "^9.0.0",
|
||||||
|
"@angular/core": "^9.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"tslib": "^2.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Why is this migration necessary?
|
||||||
|
|
||||||
|
The [`tslib`](https://github.com/Microsoft/tslib) is a runtime library for Typescript.
|
||||||
|
The version of this library is bound to the version of the TypeScript compiler used to compile a library.
|
||||||
|
Peer dependencies do not accurately represent this relationship between the runtime and the compiler.
|
||||||
|
If `tslib` remained declared as a library peer dependency, it would be possible for some Angular workspaces to get into a state where the workspace could not satisfy `tslib` peer dependency requirements for multiple libraries, resulting in build-time or run-time errors.
|
||||||
|
|
||||||
|
As of TypeScript 3.9 (used by Angular v10), `tslib` version of 2.x is required to build new applications.
|
||||||
|
However, older libraries built with previous version of TypeScript and already published to npm might need `tslib` 1.x.
|
||||||
|
This migration makes it possible for code depending on incompatible versions of the `tslib` runtime library to remain interoperable.
|
||||||
|
|
||||||
|
|
||||||
|
## Do I still need `tslib` as a dependency in my workspace `package.json`?
|
||||||
|
|
||||||
|
Yes.
|
||||||
|
The `tslib` dependency declared in the `package.json` file of the workspace is used to build applications within this workspace, as well as run unit tests for workspace libraries, and is required.
|
@ -0,0 +1,33 @@
|
|||||||
|
# Update `module` and `target` compiler options migration
|
||||||
|
|
||||||
|
## What does this migration do?
|
||||||
|
|
||||||
|
This migration adjusts the [`target`](https://www.typescriptlang.org/v2/en/tsconfig#target) and [`module`](https://www.typescriptlang.org/v2/en/tsconfig#module) settings within the [TypeScript configuration files](guide/typescript-configuration) for the workspace.
|
||||||
|
The changes to each option vary based on the builder or command that uses the TypeScript configuration file.
|
||||||
|
Unless otherwise noted, changes are only made if the existing value was not changed since the project was created.
|
||||||
|
This process helps ensure that intentional changes to the options are kept in place.
|
||||||
|
|
||||||
|
TypeScript Configuration File(s) | Changed Property | Existing Value | New Value
|
||||||
|
------------- | ------------- | ------------- | ------------- | -------------
|
||||||
|
`<workspace base>/tsconfig.base.json` | `"module"` | `"esnext"` | `"es2020"`
|
||||||
|
Used in `browser` builder options (`ng build` for applications) | `"module"` | `"esnext"` | `"es2020"`
|
||||||
|
Used in `ng-packgr` builder options (`ng build` for libraries) | `"module"` | `"esnext"` | `"es2020"`
|
||||||
|
Used in `karma` builder options (`ng test` for applications) | `"module"` | `"esnext"` | `"es2020"`
|
||||||
|
Used in `server` builder options (universal) | `"module"` | `"commonjs"` | _removed_
|
||||||
|
Used in `server` builder options (universal) | `"target"` | _any_ | `"es2016"`
|
||||||
|
Used in `protractor` builder options (`ng e2e` for applications) | `"target"` | `"es5"` | `"es2018"`
|
||||||
|
|
||||||
|
## Why is this migration necessary?
|
||||||
|
|
||||||
|
This migration provides improvements to the long-term supportability of projects by updating the projects to use recommended best practice compilation options.
|
||||||
|
|
||||||
|
For the functionality that executes on Node.js, such as Universal and Protractor, the new settings provide performance and troubleshooting benefits as well.
|
||||||
|
The minimum Node.js version for the Angular CLI (v10.13) supports features in ES2018 and earlier.
|
||||||
|
By targeting later ES versions, the compiler transforms less code and can use newer features directly.
|
||||||
|
Since zone.js does not support native `async` and `await`, the universal builds still target ES2016.
|
||||||
|
|
||||||
|
## Why `"es2020"` instead of `"esnext"`?
|
||||||
|
|
||||||
|
In TypeScript 3.9, the behavior of the TypeScript compiler controlled by `module` is the same with both `"esnext"` and `"es2020"` values.
|
||||||
|
This behavior can change in the future, because the `"esnext"` option could evolve in a backwards incompatible ways, resulting in build-time or run-time errors during a TypeScript update.
|
||||||
|
As a result, code can become unstable. Using the `"es2020"` option mitigates this risk.
|
@ -118,7 +118,6 @@ Package name | Description
|
|||||||
[**@angular‑devkit/<br />build‑angular**](https://github.com/angular/angular-cli/) | The Angular build tools.
|
[**@angular‑devkit/<br />build‑angular**](https://github.com/angular/angular-cli/) | The Angular build tools.
|
||||||
[**@angular/cli**](https://github.com/angular/angular-cli/) | The Angular CLI tools.
|
[**@angular/cli**](https://github.com/angular/angular-cli/) | The Angular CLI tools.
|
||||||
**@angular/<br />compiler‑cli** | The Angular compiler, which is invoked by the Angular CLI's `ng build` and `ng serve` commands.
|
**@angular/<br />compiler‑cli** | The Angular compiler, which is invoked by the Angular CLI's `ng build` and `ng serve` commands.
|
||||||
**@angular/<br />language‑service** | The [Angular language service](guide/language-service) analyzes component templates and provides type and error information that TypeScript-aware editors can use to improve the developer's experience. For example, see the [Angular language service extension for VS Code](https://marketplace.visualstudio.com/items?itemName=Angular.ng-template).
|
|
||||||
**@types/... ** | TypeScript definition files for 3rd party libraries such as Jasmine and Node.js.
|
**@types/... ** | TypeScript definition files for 3rd party libraries such as Jasmine and Node.js.
|
||||||
[**codelyzer**](https://www.npmjs.com/package/codelyzer) | A linter for Angular apps whose rules conform to the Angular [style guide](guide/styleguide).
|
[**codelyzer**](https://www.npmjs.com/package/codelyzer) | A linter for Angular apps whose rules conform to the Angular [style guide](guide/styleguide).
|
||||||
**jasmine/... ** | Packages to support the [Jasmine](https://jasmine.github.io/) test library.
|
**jasmine/... ** | Packages to support the [Jasmine](https://jasmine.github.io/) test library.
|
||||||
@ -135,3 +134,4 @@ Package name | Description
|
|||||||
|
|
||||||
* [Building and serving](guide/build) describes how packages come together to create a development build.
|
* [Building and serving](guide/build) describes how packages come together to create a development build.
|
||||||
* [Deployment](guide/deployment) describes how packages come together to create a production build.
|
* [Deployment](guide/deployment) describes how packages come together to create a production build.
|
||||||
|
|
@ -112,7 +112,7 @@ Because observables produce values asynchronously, try/catch will not effectivel
|
|||||||
<code-example>
|
<code-example>
|
||||||
myObservable.subscribe({
|
myObservable.subscribe({
|
||||||
next(num) { console.log('Next num: ' + num)},
|
next(num) { console.log('Next num: ' + num)},
|
||||||
error(err) { console.log('Received an errror: ' + err)}
|
error(err) { console.log('Received an error: ' + err)}
|
||||||
});
|
});
|
||||||
</code-example>
|
</code-example>
|
||||||
|
|
||||||
|
@ -1,607 +1,440 @@
|
|||||||
# Pipes
|
# Transforming Data Using Pipes
|
||||||
|
|
||||||
Every application starts out with what seems like a simple task: get data, transform them, and show them to users.
|
Use [pipes](guide/glossary#pipe "Definition of a pipe") to transform and format strings, currency amounts, dates, and other display data.
|
||||||
Getting data could be as simple as creating a local variable or as complex as streaming data over a WebSocket.
|
Pipes are simple functions you can use in [template expressions](/guide/glossary#template-expression "Definition of template expression") to accept an input value and return a transformed value.
|
||||||
|
For example, you would use a pipe to show a date as **April 15, 1988** rather than the raw string format.
|
||||||
|
|
||||||
<div class="alert is-helpful">
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
For the sample app that this page describes, see the <live-example></live-example>.
|
For the sample app used in this topic, see the <live-example></live-example>.
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
Once data arrives, you could push their raw `toString` values directly to the view,
|
Angular provides built-in pipes for typical data transformations, including transformations for internationalization (i18n), which use locale information to format data.
|
||||||
but that rarely makes for a good user experience.
|
The following are commonly used built-in pipes for data formatting:
|
||||||
For example, in most use cases, users prefer to see a date in a simple format like
|
|
||||||
<samp>April 15, 1988</samp> rather than the raw string format
|
|
||||||
<samp>Fri Apr 15 1988 00:00:00 GMT-0700 (Pacific Daylight Time)</samp>.
|
|
||||||
|
|
||||||
Clearly, some values benefit from a bit of editing. You may notice that you
|
|
||||||
desire many of the same transformations repeatedly, both within and across many applications.
|
|
||||||
You can almost think of them as styles.
|
|
||||||
In fact, you might like to apply them in your HTML templates as you do styles.
|
|
||||||
|
|
||||||
Introducing Angular pipes, a way to write display-value transformations that you can declare in your HTML.
|
|
||||||
|
|
||||||
|
|
||||||
## Using pipes
|
|
||||||
|
|
||||||
A pipe takes in data as input and transforms it to a desired output.
|
|
||||||
In this page, you'll use pipes to transform a component's birthday property into
|
|
||||||
a human-friendly date.
|
|
||||||
|
|
||||||
|
|
||||||
<code-example path="pipes/src/app/hero-birthday1.component.ts" header="src/app/hero-birthday1.component.ts"></code-example>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Focus on the component's template.
|
|
||||||
|
|
||||||
|
|
||||||
<code-example path="pipes/src/app/app.component.html" region="hero-birthday-template" header="src/app/app.component.html"></code-example>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Inside the interpolation expression, you flow the component's `birthday` value through the
|
|
||||||
[pipe operator](guide/template-syntax#pipe) ( | ) to the [Date pipe](api/common/DatePipe)
|
|
||||||
function on the right. All pipes work this way.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Built-in pipes
|
|
||||||
Angular comes with a stock of pipes such as
|
|
||||||
`DatePipe`, `UpperCasePipe`, `LowerCasePipe`, `CurrencyPipe`, and `PercentPipe`.
|
|
||||||
They are all available for use in any template.
|
|
||||||
|
|
||||||
|
* [`DatePipe`](api/common/DatePipe): Formats a date value according to locale rules.
|
||||||
|
* [`UpperCasePipe`](api/common/UpperCasePipe): Transforms text to all upper case.
|
||||||
|
* [`LowerCasePipe`](api/common/LowerCasePipe): Transforms text to all lower case.
|
||||||
|
* [`CurrencyPipe`](api/common/CurrencyPipe): Transforms a number to a currency string, formatted according to locale rules.
|
||||||
|
* [`DecimalPipe`](/api/common/DecimalPipe): Transforms a number into a string with a decimal point, formatted according to locale rules.
|
||||||
|
* [`PercentPipe`](api/common/PercentPipe): Transforms a number to a percentage string, formatted according to locale rules.
|
||||||
|
|
||||||
<div class="alert is-helpful">
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
* For a complete list of built-in pipes, see the [pipes API documentation](/api/common#pipes "Pipes API reference summary").
|
||||||
|
* To learn more about using pipes for internationalization (i18n) efforts, see [formatting data based on locale](/guide/i18n#i18n-pipes "Formatting data based on locale").
|
||||||
Read more about these and many other built-in pipes in the [pipes topics](api?type=pipe) of the
|
|
||||||
[API Reference](api); filter for entries that include the word "pipe".
|
|
||||||
|
|
||||||
Angular doesn't have a `FilterPipe` or an `OrderByPipe` for reasons explained in the [Appendix](guide/pipes#no-filter-pipe) of this page.
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
You can also create pipes to encapsulate custom transformations and use your custom pipes in template expressions.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
To use pipes you should have a basic understanding of the following:
|
||||||
|
|
||||||
## Parameterizing a pipe
|
* [Typescript](guide/glossary#typescript "Definition of Typescript") and HTML5 programming
|
||||||
|
* [Templates](guide/glossary#template "Definition of a template") in HTML with CSS styles
|
||||||
|
* [Components](guide/glossary#component "Definition of a component")
|
||||||
|
|
||||||
A pipe can accept any number of optional parameters to fine-tune its output.
|
## Using a pipe in a template
|
||||||
To add parameters to a pipe, follow the pipe name with a colon ( : ) and then the parameter value
|
|
||||||
(such as `currency:'EUR'`). If the pipe accepts multiple parameters, separate the values with colons (such as `slice:1:5`)
|
|
||||||
|
|
||||||
Modify the birthday template to give the date pipe a format parameter.
|
To apply a pipe, use the pipe operator (`|`) within a template expression as shown in the following code example, along with the *name* of the pipe, which is `date` for the built-in [`DatePipe`](api/common/DatePipe).
|
||||||
After formatting the hero's April 15th birthday, it renders as **<samp>04/15/88</samp>**:
|
The tabs in the example show the following:
|
||||||
|
|
||||||
|
* `app.component.html` uses `date` in a separate template to display a birthday.
|
||||||
|
* `hero-birthday1.component.ts` uses the same pipe as part of an in-line template in a component that also sets the birthday value.
|
||||||
|
|
||||||
<code-example path="pipes/src/app/app.component.html" region="format-birthday" header="src/app/app.component.html"></code-example>
|
<code-tabs>
|
||||||
|
<code-pane
|
||||||
|
header="src/app/app.component.html"
|
||||||
|
region="hero-birthday-template"
|
||||||
|
path="pipes/src/app/app.component.html">
|
||||||
|
</code-pane>
|
||||||
|
<code-pane
|
||||||
|
header="src/app/hero-birthday1.component.ts"
|
||||||
|
path="pipes/src/app/hero-birthday1.component.ts">
|
||||||
|
</code-pane>
|
||||||
|
</code-tabs>
|
||||||
|
|
||||||
|
The component's `birthday` value flows through the
|
||||||
|
[pipe operator](guide/template-syntax#pipe) ( | ) to the [`date`](api/common/DatePipe)
|
||||||
|
function.
|
||||||
|
|
||||||
|
{@a parameterizing-a-pipe}
|
||||||
|
|
||||||
The parameter value can be any valid template expression,
|
## Formatting data with parameters and chained pipes
|
||||||
(see the [Template expressions](guide/template-syntax#template-expressions) section of the
|
|
||||||
[Template Syntax](guide/template-syntax) page)
|
|
||||||
such as a string literal or a component property.
|
|
||||||
In other words, you can control the format through a binding the same way you control the birthday value through a binding.
|
|
||||||
|
|
||||||
Write a second component that *binds* the pipe's format parameter
|
Use optional parameters to fine-tune a pipe's output.
|
||||||
to the component's `format` property. Here's the template for that component:
|
For example, you can use the [`CurrencyPipe`](api/common/CurrencyPipe "API reference") with a country code such as EUR as a parameter.
|
||||||
|
The template expression `{{ amount | currency:'EUR' }}` transforms the `amount` to currency in euros.
|
||||||
|
Follow the pipe name (`currency`) with a colon (`:`) and the parameter value (`'EUR'`).
|
||||||
|
|
||||||
|
If the pipe accepts multiple parameters, separate the values with colons.
|
||||||
|
For example, `{{ amount | currency:'EUR':'Euros '}}` adds the second parameter, the string literal `'Euros '`, to the output string. You can use any valid template expression as a parameter, such as a string literal or a component property.
|
||||||
|
|
||||||
<code-example path="pipes/src/app/hero-birthday2.component.ts" region="template" header="src/app/hero-birthday2.component.ts (template)"></code-example>
|
Some pipes require at least one parameter and allow more optional parameters, such as [`SlicePipe`](/api/common/SlicePipe "API reference for SlicePipe"). For example, `{{ slice:1:5 }}` creates a new array or string containing a subset of the elements starting with element `1` and ending with element `5`.
|
||||||
|
|
||||||
|
### Example: Formatting a date
|
||||||
|
|
||||||
|
The tabs in the following example demonstrates toggling between two different formats (`'shortDate'` and `'fullDate'`):
|
||||||
|
|
||||||
You also added a button to the template and bound its click event to the component's `toggleFormat()` method.
|
* The `app.component.html` template uses a format parameter for the [`DatePipe`](api/common/DatePipe) (named `date`) to show the date as **04/15/88**.
|
||||||
That method toggles the component's `format` property between a short form
|
* The `hero-birthday2.component.ts` component binds the pipe's format parameter to the component's `format` property in the `template` section, and adds a button for a click event bound to the component's `toggleFormat()` method.
|
||||||
|
* The `hero-birthday2.component.ts` component's `toggleFormat()` method toggles the component's `format` property between a short form
|
||||||
(`'shortDate'`) and a longer form (`'fullDate'`).
|
(`'shortDate'`) and a longer form (`'fullDate'`).
|
||||||
|
|
||||||
|
<code-tabs>
|
||||||
|
<code-pane
|
||||||
|
header="src/app/app.component.html"
|
||||||
|
region="format-birthday"
|
||||||
|
path="pipes/src/app/app.component.html">
|
||||||
|
</code-pane>
|
||||||
|
<code-pane
|
||||||
|
header="src/app/hero-birthday2.component.ts (template)"
|
||||||
|
region="template"
|
||||||
|
path="pipes/src/app/hero-birthday2.component.ts">
|
||||||
|
</code-pane>
|
||||||
|
<code-pane
|
||||||
|
header="src/app/hero-birthday2.component.ts (class)"
|
||||||
|
region="class"
|
||||||
|
path="pipes/src/app/hero-birthday2.component.ts">
|
||||||
|
</code-pane>
|
||||||
|
</code-tabs>
|
||||||
|
|
||||||
<code-example path="pipes/src/app/hero-birthday2.component.ts" region="class" header="src/app/hero-birthday2.component.ts (class)"></code-example>
|
Clicking the **Toggle Format** button alternates the date format between **04/15/1988** and **Friday, April 15, 1988** as shown in Figure 1.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
As you click the button, the displayed date alternates between
|
|
||||||
"**<samp>04/15/1988</samp>**" and
|
|
||||||
"**<samp>Friday, April 15, 1988</samp>**".
|
|
||||||
|
|
||||||
<div class="lightbox">
|
<div class="lightbox">
|
||||||
<img src='generated/images/guide/pipes/date-format-toggle-anim.gif' alt="Date Format Toggle">
|
<img src='generated/images/guide/pipes/date-format-toggle-anim.gif' alt="Date Format Toggle">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
**Figure 1.** Clicking the button toggles the date format
|
||||||
|
|
||||||
<div class="alert is-helpful">
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
For `date` pipe format options, see [DatePipe](api/common/DatePipe "DatePipe API Reference page").
|
||||||
|
|
||||||
Read more about the `DatePipe` format options in the [Date Pipe](api/common/DatePipe)
|
|
||||||
API Reference page.
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
### Example: Applying two formats by chaining pipes
|
||||||
|
|
||||||
|
You can chain pipes so that the output of one pipe becomes the input to the next.
|
||||||
|
|
||||||
## Chaining pipes
|
In the following example, chained pipes first apply a format to a date value, then convert the formatted date to uppercase characters.
|
||||||
|
The first tab for the `src/app/app.component.html` template chains `DatePipe` and `UpperCasePipe` to display the birthday as **APR 15, 1988**.
|
||||||
|
The second tab for the `src/app/app.component.html` template passes the `fullDate` parameter to `date` before chaining to `uppercase`, which produces **FRIDAY, APRIL 15, 1988**.
|
||||||
|
|
||||||
You can chain pipes together in potentially useful combinations.
|
<code-tabs>
|
||||||
In the following example, to display the birthday in uppercase,
|
<code-pane
|
||||||
the birthday is chained to the `DatePipe` and on to the `UpperCasePipe`.
|
header="src/app/app.component.html (1)"
|
||||||
The birthday displays as **<samp>APR 15, 1988</samp>**.
|
region="chained-birthday"
|
||||||
|
path="pipes/src/app/app.component.html">
|
||||||
|
</code-pane>
|
||||||
|
<code-pane
|
||||||
|
header="src/app/app.component.html (2)"
|
||||||
|
region="chained-parameter-birthday"
|
||||||
|
path="pipes/src/app/app.component.html">
|
||||||
|
</code-pane>
|
||||||
|
</code-tabs>
|
||||||
|
|
||||||
|
{@a Custom-pipes}
|
||||||
|
|
||||||
<code-example path="pipes/src/app/app.component.html" region="chained-birthday" header="src/app/app.component.html"></code-example>
|
## Creating pipes for custom data transformations
|
||||||
|
|
||||||
|
Create custom pipes to encapsulate transformations that are not provided with the built-in pipes.
|
||||||
|
You can then use your custom pipe in template expressions, the same way you use built-in pipes—to transform input values to output values for display.
|
||||||
|
|
||||||
|
### Marking a class as a pipe
|
||||||
|
|
||||||
This example—which displays **<samp>FRIDAY, APRIL 15, 1988</samp>**—chains
|
To mark a class as a pipe and supply configuration metadata, apply the [`@Pipe`](/api/core/Pipe "API reference for Pipe") [decorator](/guide/glossary#decorator--decoration "Definition for decorator") to the class.
|
||||||
the same pipes as above, but passes in a parameter to `date` as well.
|
Use [UpperCamelCase](guide/glossary#case-types "Definition of case types") (the general convention for class names) for the pipe class name, and [camelCase](guide/glossary#case-types "Definition of case types") for the corresponding `name` string.
|
||||||
|
Do not use hyphens in the `name`.
|
||||||
|
For details and more examples, see [Pipe names](guide/styleguide#pipe-names "Pipe names in the Angular coding style guide").
|
||||||
|
|
||||||
|
Use `name` in template expressions as you would for a built-in pipe.
|
||||||
|
|
||||||
<code-example path="pipes/src/app/app.component.html" region="chained-parameter-birthday" header="src/app/app.component.html"></code-example>
|
<div class="alert is-important">
|
||||||
|
|
||||||
|
* Include your pipe in the `declarations` field of the `NgModule` metadata in order for it to be available to a template. See the `app.module.ts` file in the example app (<live-example></live-example>). For details, see [NgModules](guide/ngmodules "NgModules introduction").
|
||||||
|
* Register your custom pipes. The [Angular CLI](cli "CLI Overview and Command Reference") [`ng generate pipe`](cli/generate#pipe "ng generate pipe in the CLI Command Reference") command registers the pipe automatically.
|
||||||
|
|
||||||
## Custom pipes
|
|
||||||
|
|
||||||
You can write your own custom pipes.
|
|
||||||
Here's a custom pipe named `ExponentialStrengthPipe` that can boost a hero's powers:
|
|
||||||
|
|
||||||
|
|
||||||
<code-example path="pipes/src/app/exponential-strength.pipe.ts" header="src/app/exponential-strength.pipe.ts"></code-example>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
This pipe definition reveals the following key points:
|
|
||||||
|
|
||||||
* A pipe is a class decorated with pipe metadata.
|
|
||||||
* The pipe class implements the `PipeTransform` interface's `transform` method that
|
|
||||||
accepts an input value followed by optional parameters and returns the transformed value.
|
|
||||||
* There will be one additional argument to the `transform` method for each parameter passed to the pipe.
|
|
||||||
Your pipe has one such parameter: the `exponent`.
|
|
||||||
* To tell Angular that this is a pipe, you apply the
|
|
||||||
`@Pipe` decorator, which you import from the core Angular library.
|
|
||||||
* The `@Pipe` decorator allows you to define the
|
|
||||||
pipe name that you'll use within template expressions. It must be a valid JavaScript identifier.
|
|
||||||
Your pipe's name is `exponentialStrength`.
|
|
||||||
|
|
||||||
|
|
||||||
<div class="alert is-helpful">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## The *PipeTransform* interface
|
|
||||||
|
|
||||||
The `transform` method is essential to a pipe.
|
|
||||||
The `PipeTransform` *interface* defines that method and guides both tooling and the compiler.
|
|
||||||
Technically, it's optional; Angular looks for and executes the `transform` method regardless.
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
Now you need a component to demonstrate the pipe.
|
### Using the PipeTransform interface
|
||||||
|
|
||||||
<code-example path="pipes/src/app/power-booster.component.ts" header="src/app/power-booster.component.ts"></code-example>
|
Implement the [`PipeTransform`](/api/core/PipeTransform "API reference for PipeTransform") interface in your custom pipe class to perform the transformation.
|
||||||
|
|
||||||
|
Angular invokes the `transform` method with the value of a binding as the first argument, and any parameters as the second argument in list form, and returns the transformed value.
|
||||||
|
|
||||||
|
### Example: Transforming a value exponentially
|
||||||
|
|
||||||
|
In a game, you may want to implement a transformation that raises a value exponentially to increase a hero's power.
|
||||||
|
For example, if the hero's score is 2, boosting the hero's power exponentially by 10 produces a score of 1024.
|
||||||
|
You can use a custom pipe for this transformation.
|
||||||
|
|
||||||
|
The following code example shows two component definitions:
|
||||||
|
|
||||||
|
* The `exponential-strength.pipe.ts` component defines a custom pipe named `exponentialStrength` with the `transform` method that performs the transformation.
|
||||||
|
It defines an argument to the `transform` method (`exponent`) for a parameter passed to the pipe.
|
||||||
|
|
||||||
|
* The `power-booster.component.ts` component demonstrates how to use the pipe, specifying a value (`2`) and the exponent parameter (`10`).
|
||||||
|
Figure 2 shows the output.
|
||||||
|
|
||||||
|
<code-tabs>
|
||||||
|
<code-pane
|
||||||
|
header="src/app/exponential-strength.pipe.ts"
|
||||||
|
path="pipes/src/app/exponential-strength.pipe.ts">
|
||||||
|
</code-pane>
|
||||||
|
<code-pane
|
||||||
|
header="src/app/power-booster.component.ts"
|
||||||
|
path="pipes/src/app/power-booster.component.ts">
|
||||||
|
</code-pane>
|
||||||
|
</code-tabs>
|
||||||
|
|
||||||
<div class="lightbox">
|
<div class="lightbox">
|
||||||
<img src='generated/images/guide/pipes/power-booster.png' alt="Power Booster">
|
<img src='generated/images/guide/pipes/power-booster.png' alt="Power Booster">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
**Figure 2.** Output from the `exponentialStrength` pipe
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
Note the following:
|
To examine the behavior the `exponentialStrength` pipe in the <live-example></live-example>, change the value and optional exponent in the template.
|
||||||
|
|
||||||
* You use your custom pipe the same way you use built-in pipes.
|
|
||||||
* You must include your pipe in the `declarations` array of the `AppModule`
|
|
||||||
* If you choose to inject your pipe into a class, you must provide it in the `providers` array of your `NgModule`.
|
|
||||||
|
|
||||||
<div class="callout is-helpful">
|
|
||||||
|
|
||||||
<header>
|
|
||||||
Remember the declarations array
|
|
||||||
</header>
|
|
||||||
|
|
||||||
|
|
||||||
You must register custom pipes.
|
|
||||||
If you don't, Angular reports an error.
|
|
||||||
The [Angular CLI's](cli) generator registers the pipe automatically.
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{@a change-detection}
|
||||||
|
|
||||||
|
## Detecting changes with data binding in pipes
|
||||||
|
|
||||||
To probe the behavior in the <live-example></live-example>,
|
You use [data binding](/guide/glossary#data-binding "Definition of data binding") with a pipe to display values and respond to user actions.
|
||||||
change the value and optional exponent in the template.
|
If the data is a primitive input value, such as `String` or `Number`, or an object reference as input, such as `Date` or `Array`, Angular executes the pipe whenever it detects a change for the input value or reference.
|
||||||
|
|
||||||
## Power Boost Calculator
|
|
||||||
|
|
||||||
It's not much fun updating the template to test the custom pipe.
|
|
||||||
Upgrade the example to a "Power Boost Calculator" that combines
|
|
||||||
your pipe and two-way data binding with `ngModel`.
|
|
||||||
|
|
||||||
|
For example, you could change the previous custom pipe example to use two-way data binding with `ngModel` to input the amount and boost factor, as shown in the following code example.
|
||||||
|
|
||||||
<code-example path="pipes/src/app/power-boost-calculator.component.ts" header="src/app/power-boost-calculator.component.ts">
|
<code-example path="pipes/src/app/power-boost-calculator.component.ts" header="src/app/power-boost-calculator.component.ts">
|
||||||
|
|
||||||
</code-example>
|
</code-example>
|
||||||
|
|
||||||
|
The `exponentialStrength` pipe executes every time the user changes the "normal power" value or the "boost factor", as shown in Figure 3.
|
||||||
|
|
||||||
<div class="lightbox">
|
<div class="lightbox">
|
||||||
<img src='generated/images/guide/pipes/power-boost-calculator-anim.gif' alt="Power Boost Calculator">
|
<img src='generated/images/guide/pipes/power-boost-calculator-anim.gif' alt="Power Boost Calculator">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
**Figure 3.** Changing the amount and boost factor for the `exponentialStrength` pipe
|
||||||
|
|
||||||
|
Angular detects each change and immediately runs the pipe.
|
||||||
|
This is fine for primitive input values.
|
||||||
|
However, if you change something *inside* a composite object (such as the month of a date, an element of an array, or an object property), you need to understand how change detection works, and how to use an `impure` pipe.
|
||||||
|
|
||||||
|
### How change detection works
|
||||||
|
|
||||||
{@a change-detection}
|
Angular looks for changes to data-bound values in a [change detection](guide/glossary#change-detection "Definition of change detection") process that runs after every DOM event: every keystroke, mouse move, timer tick, and server response.
|
||||||
|
The following example, which doesn't use a pipe, demonstrates how Angular uses its default change detection strategy to monitor and update its display of every hero in the `heroes` array.
|
||||||
|
The example tabs show the following:
|
||||||
|
|
||||||
|
* In the `flying-heroes.component.html (v1)` template, the `*ngFor` repeater displays the hero names.
|
||||||
|
* Its companion component class `flying-heroes.component.ts (v1)` provides heroes, adds heroes into the array, and resets the array.
|
||||||
|
|
||||||
## Pipes and change detection
|
<code-tabs>
|
||||||
|
<code-pane
|
||||||
|
header="src/app/flying-heroes.component.html (v1)"
|
||||||
|
region="template-1"
|
||||||
|
path="pipes/src/app/flying-heroes.component.html">
|
||||||
|
</code-pane>
|
||||||
|
<code-pane
|
||||||
|
header="src/app/flying-heroes.component.ts (v1)"
|
||||||
|
region="v1"
|
||||||
|
path="pipes/src/app/flying-heroes.component.ts">
|
||||||
|
</code-pane>
|
||||||
|
</code-tabs>
|
||||||
|
|
||||||
Angular looks for changes to data-bound values through a *change detection* process that runs after every DOM event:
|
Angular updates the display every time the user adds a hero.
|
||||||
every keystroke, mouse move, timer tick, and server response. This could be expensive.
|
If the user clicks the **Reset** button, Angular replaces `heroes` with a new array of the original heroes and updates the display.
|
||||||
Angular strives to lower the cost whenever possible and appropriate.
|
If you add the ability to remove or change a hero, Angular would detect those changes and update the display as well.
|
||||||
|
|
||||||
Angular picks a simpler, faster change detection algorithm when you use a pipe.
|
However, executing a pipe to update the display with every change would slow down your app's performance.
|
||||||
|
So Angular uses a faster change-detection algorithm for executing a pipe, as described in the next section.
|
||||||
|
|
||||||
<h3 class="no-toc">No pipe</h3>
|
{@a pure-and-impure-pipes}
|
||||||
|
|
||||||
In the next example, the component uses the default, aggressive change detection strategy to monitor and update
|
### Detecting pure changes to primitives and object references
|
||||||
its display of every hero in the `heroes` array. Here's the template:
|
|
||||||
|
|
||||||
|
By default, pipes are defined as *pure* so that Angular executes the pipe only when it detects a *pure change* to the input value.
|
||||||
|
A pure change is either a change to a primitive input value (such as `String`, `Number`, `Boolean`, or `Symbol`), or a changed object reference (such as `Date`, `Array`, `Function`, or `Object`).
|
||||||
|
|
||||||
<code-example path="pipes/src/app/flying-heroes.component.html" region="template-1" header="src/app/flying-heroes.component.html (v1)"></code-example>
|
{@a pure-pipe-pure-fn}
|
||||||
|
|
||||||
|
A pure pipe must use a pure function, which is one that processes inputs and returns values without side effects.
|
||||||
|
In other words, given the same input, a pure function should always return the same output.
|
||||||
|
|
||||||
|
With a pure pipe, Angular ignores changes within composite objects, such as a newly added element of an existing array, because checking a primitive value or object reference is much faster than performing a deep check for differences within objects.
|
||||||
|
Angular can quickly determine if it can skip executing the pipe and updating the view.
|
||||||
|
|
||||||
The companion component class provides heroes, adds heroes into the array, and can reset the array.
|
However, a pure pipe with an array as input may not work the way you want.
|
||||||
|
To demonstrate this issue, change the previous example to filter the list of heroes to just those heroes who can fly.
|
||||||
|
Use the `FlyingHeroesPipe` in the `*ngFor` repeater as shown in the following code.
|
||||||
|
The tabs for the example show the following:
|
||||||
|
|
||||||
<code-example path="pipes/src/app/flying-heroes.component.ts" region="v1" header="src/app/flying-heroes.component.ts (v1)"></code-example>
|
* The template (`flying-heroes.component.html (flyers)`) with the new pipe.
|
||||||
|
* The `FlyingHeroesPipe` custom pipe implementation (`flying-heroes.pipe.ts`).
|
||||||
|
|
||||||
|
<code-tabs>
|
||||||
|
<code-pane
|
||||||
|
header="src/app/flying-heroes.component.html (flyers)"
|
||||||
|
region="template-flying-heroes"
|
||||||
|
path="pipes/src/app/flying-heroes.component.html">
|
||||||
|
</code-pane>
|
||||||
|
<code-pane
|
||||||
|
header="src/app/flying-heroes.pipe.ts"
|
||||||
|
region="pure"
|
||||||
|
path="pipes/src/app/flying-heroes.pipe.ts">
|
||||||
|
</code-pane>
|
||||||
|
</code-tabs>
|
||||||
|
|
||||||
|
The app now shows unexpected behavior: When the user adds flying heroes, none of them appear under "Heroes who fly."
|
||||||
You can add heroes and Angular updates the display when you do.
|
This happens because the code that adds a hero does so by pushing it onto the `heroes` array:
|
||||||
If you click the `reset` button, Angular replaces `heroes` with a new array of the original heroes and updates the display.
|
|
||||||
If you added the ability to remove or change a hero, Angular would detect those changes and update the display as well.
|
|
||||||
|
|
||||||
<h3 class="no-toc"><i>FlyingHeroesPipe</i></h3>
|
|
||||||
|
|
||||||
Add a `FlyingHeroesPipe` to the `*ngFor` repeater that filters the list of heroes to just those heroes who can fly.
|
|
||||||
|
|
||||||
<code-example path="pipes/src/app/flying-heroes.component.html" region="template-flying-heroes" header="src/app/flying-heroes.component.html (flyers)"></code-example>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Here's the `FlyingHeroesPipe` implementation, which follows the pattern for custom pipes described earlier.
|
|
||||||
|
|
||||||
<code-example path="pipes/src/app/flying-heroes.pipe.ts" region="pure" header="src/app/flying-heroes.pipe.ts"></code-example>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Notice the odd behavior in the <live-example></live-example>:
|
|
||||||
when you add flying heroes, none of them are displayed under "Heroes who fly."
|
|
||||||
|
|
||||||
Although you're not getting the behavior you want, Angular isn't broken.
|
|
||||||
It's just using a different change-detection algorithm that ignores changes to the list or any of its items.
|
|
||||||
|
|
||||||
Notice how a hero is added:
|
|
||||||
|
|
||||||
<code-example path="pipes/src/app/flying-heroes.component.ts" region="push" header="src/app/flying-heroes.component.ts"></code-example>
|
<code-example path="pipes/src/app/flying-heroes.component.ts" region="push" header="src/app/flying-heroes.component.ts"></code-example>
|
||||||
|
|
||||||
|
The change detector ignores changes to elements of an array, so the pipe doesn't run.
|
||||||
|
|
||||||
|
The reason Angular ignores the changed array element is that the *reference* to the array hasn't changed.
|
||||||
|
Since the array is the same, Angular does not update the display.
|
||||||
|
|
||||||
You add the hero into the `heroes` array. The reference to the array hasn't changed.
|
One way to get the behavior you want is to change the object reference itself.
|
||||||
It's the same array. That's all Angular cares about. From its perspective, *same array, no change, no display update*.
|
You can replace the array with a new array containing the newly changed elements, and then input the new array to the pipe.
|
||||||
|
In the above example, you can create an array with the new hero appended, and assign that to `heroes`. Angular detects the change in the array reference and executes the pipe.
|
||||||
To fix that, create an array with the new hero appended and assign that to `heroes`.
|
|
||||||
This time Angular detects that the array reference has changed.
|
|
||||||
It executes the pipe and updates the display with the new array, which includes the new flying hero.
|
|
||||||
|
|
||||||
If you *mutate* the array, no pipe is invoked and the display isn't updated;
|
|
||||||
if you *replace* the array, the pipe executes and the display is updated.
|
|
||||||
The Flying Heroes application extends the
|
|
||||||
code with checkbox switches and additional displays to help you experience these effects.
|
|
||||||
|
|
||||||
|
To summarize, if you mutate the input array, the pure pipe doesn't execute.
|
||||||
|
If you *replace* the input array, the pipe executes and the display is updated, as shown in Figure 4.
|
||||||
|
|
||||||
<div class="lightbox">
|
<div class="lightbox">
|
||||||
<img src='generated/images/guide/pipes/flying-heroes-anim.gif' alt="Flying Heroes">
|
<img src='generated/images/guide/pipes/flying-heroes-anim.gif' alt="Flying Heroes">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
**Figure 4.** The `flyingHeroes` pipe filtering the display to flying heroes
|
||||||
|
|
||||||
|
The above example demonstrates changing a component's code to accommodate a pipe.
|
||||||
|
|
||||||
Replacing the array is an efficient way to signal Angular to update the display.
|
To keep your component simpler and independent of HTML templates that use pipes, you can, as an alternative, use an *impure* pipe to detect changes within composite objects such as arrays, as described in the next section.
|
||||||
When do you replace the array? When the data changes.
|
|
||||||
That's an easy rule to follow in *this* example
|
|
||||||
where the only way to change the data is by adding a hero.
|
|
||||||
|
|
||||||
More often, you don't know when the data has changed,
|
|
||||||
especially in applications that mutate data in many ways,
|
|
||||||
perhaps in application locations far away.
|
|
||||||
A component in such an application usually can't know about those changes.
|
|
||||||
Moreover, it's unwise to distort the component design to accommodate a pipe.
|
|
||||||
Strive to keep the component class independent of the HTML.
|
|
||||||
The component should be unaware of pipes.
|
|
||||||
|
|
||||||
For filtering flying heroes, consider an *impure pipe*.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Pure and impure pipes
|
|
||||||
|
|
||||||
There are two categories of pipes: *pure* and *impure*.
|
|
||||||
Pipes are pure by default. Every pipe you've seen so far has been pure.
|
|
||||||
You make a pipe impure by setting its pure flag to false. You could make the `FlyingHeroesPipe`
|
|
||||||
impure like this:
|
|
||||||
|
|
||||||
|
|
||||||
<code-example path="pipes/src/app/flying-heroes.pipe.ts" region="pipe-decorator" header="src/app/flying-heroes.pipe.ts"></code-example>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Before doing that, understand the difference between pure and impure, starting with a pure pipe.
|
|
||||||
|
|
||||||
<h3 class="no-toc">Pure pipes</h3>
|
|
||||||
|
|
||||||
Angular executes a *pure pipe* only when it detects a *pure change* to the input value.
|
|
||||||
A pure change is either a change to a primitive input value (`String`, `Number`, `Boolean`, `Symbol`)
|
|
||||||
or a changed object reference (`Date`, `Array`, `Function`, `Object`).
|
|
||||||
|
|
||||||
Angular ignores changes within (composite) objects.
|
|
||||||
It won't call a pure pipe if you change an input month, add to an input array, or update an input object property.
|
|
||||||
|
|
||||||
This may seem restrictive but it's also fast.
|
|
||||||
An object reference check is fast—much faster than a deep check for
|
|
||||||
differences—so Angular can quickly determine if it can skip both the
|
|
||||||
pipe execution and a view update.
|
|
||||||
|
|
||||||
For this reason, a pure pipe is preferable when you can live with the change detection strategy.
|
|
||||||
When you can't, you *can* use the impure pipe.
|
|
||||||
|
|
||||||
|
|
||||||
<div class="alert is-helpful">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Or you might not use a pipe at all.
|
|
||||||
It may be better to pursue the pipe's purpose with a property of the component,
|
|
||||||
a point that's discussed later in this page.
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3 class="no-toc">Impure pipes</h3>
|
|
||||||
|
|
||||||
Angular executes an *impure pipe* during every component change detection cycle.
|
|
||||||
An impure pipe is called often, as often as every keystroke or mouse-move.
|
|
||||||
|
|
||||||
With that concern in mind, implement an impure pipe with great care.
|
|
||||||
An expensive, long-running pipe could destroy the user experience.
|
|
||||||
|
|
||||||
|
|
||||||
{@a impure-flying-heroes}
|
{@a impure-flying-heroes}
|
||||||
|
|
||||||
|
### Detecting impure changes within composite objects
|
||||||
|
|
||||||
<h3 class="no-toc">An impure <i>FlyingHeroesPipe</i></h3>
|
To execute a custom pipe after a change *within* a composite object, such as a change to an element of an array, you need to define your pipe as `impure` to detect impure changes.
|
||||||
|
Angular executes an impure pipe every time it detects a change with every keystroke or mouse movement.
|
||||||
|
|
||||||
A flip of the switch turns the `FlyingHeroesPipe` into a `FlyingHeroesImpurePipe`.
|
<div class="alert is-important">
|
||||||
The complete implementation is as follows:
|
|
||||||
|
While an impure pipe can be useful, be careful using one. A long-running impure pipe could dramatically slow down your app.
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
Make a pipe impure by setting its `pure` flag to `false`:
|
||||||
|
|
||||||
|
<code-example path="pipes/src/app/flying-heroes.pipe.ts" region="pipe-decorator" header="src/app/flying-heroes.pipe.ts"></code-example>
|
||||||
|
|
||||||
|
The following code shows the complete implementation of `FlyingHeroesImpurePipe`, which extends `FlyingHeroesPipe` to inherit its characteristics.
|
||||||
|
The example shows that you don't have to change anything else—the only difference is setting the `pure` flag as `false` in the pipe metadata.
|
||||||
|
|
||||||
<code-tabs>
|
<code-tabs>
|
||||||
|
<code-pane
|
||||||
<code-pane header="FlyingHeroesImpurePipe" path="pipes/src/app/flying-heroes.pipe.ts" region="impure">
|
header="src/app/flying-heroes.pipe.ts (FlyingHeroesImpurePipe)"
|
||||||
|
region="impure"
|
||||||
|
path="pipes/src/app/flying-heroes.pipe.ts">
|
||||||
</code-pane>
|
</code-pane>
|
||||||
|
<code-pane
|
||||||
<code-pane header="FlyingHeroesPipe" path="pipes/src/app/flying-heroes.pipe.ts" region="pure">
|
header="src/app/flying-heroes.pipe.ts (FlyingHeroesPipe)"
|
||||||
|
region="pure"
|
||||||
|
path="pipes/src/app/flying-heroes.pipe.ts">
|
||||||
</code-pane>
|
</code-pane>
|
||||||
|
|
||||||
</code-tabs>
|
</code-tabs>
|
||||||
|
|
||||||
|
`FlyingHeroesImpurePipe` is a good candidate for an impure pipe because the `transform` function is trivial and fast:
|
||||||
|
|
||||||
You inherit from `FlyingHeroesPipe` to prove the point that nothing changed internally.
|
|
||||||
The only difference is the `pure` flag in the pipe metadata.
|
|
||||||
|
|
||||||
This is a good candidate for an impure pipe because the `transform` function is trivial and fast.
|
|
||||||
|
|
||||||
|
|
||||||
<code-example path="pipes/src/app/flying-heroes.pipe.ts" header="src/app/flying-heroes.pipe.ts (filter)" region="filter"></code-example>
|
<code-example path="pipes/src/app/flying-heroes.pipe.ts" header="src/app/flying-heroes.pipe.ts (filter)" region="filter"></code-example>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
You can derive a `FlyingHeroesImpureComponent` from `FlyingHeroesComponent`.
|
You can derive a `FlyingHeroesImpureComponent` from `FlyingHeroesComponent`.
|
||||||
|
As shown in the code below, only the pipe in the template changes.
|
||||||
|
|
||||||
<code-example path="pipes/src/app/flying-heroes-impure.component.html" header="src/app/flying-heroes-impure.component.html (excerpt)" region="template-flying-heroes"></code-example>
|
<code-example path="pipes/src/app/flying-heroes-impure.component.html" header="src/app/flying-heroes-impure.component.html (excerpt)" region="template-flying-heroes"></code-example>
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
To confirm that the display updates as the user adds heroes, see the <live-example></live-example>.
|
||||||
|
|
||||||
The only substantive change is the pipe in the template.
|
</div>
|
||||||
You can confirm in the <live-example></live-example> that the _flying heroes_
|
|
||||||
display updates as you add heroes, even when you mutate the `heroes` array.
|
|
||||||
|
|
||||||
|
|
||||||
{@a async-pipe}
|
{@a async-pipe}
|
||||||
<h3 class="no-toc">The impure <i>AsyncPipe</i></h3>
|
|
||||||
|
|
||||||
|
## Unwrapping data from an observable
|
||||||
|
|
||||||
The Angular `AsyncPipe` is an interesting example of an impure pipe.
|
[Observables](/guide/glossary#observable "Definition of observable") let you pass messages between parts of your application.
|
||||||
The `AsyncPipe` accepts a `Promise` or `Observable` as input
|
Observables are recommended for event handling, asynchronous programming, and handling multiple values.
|
||||||
and subscribes to the input automatically, eventually returning the emitted values.
|
Observables can deliver single or multiple values of any type, either synchronously (as a function delivers a value to its caller) or asynchronously on a schedule.
|
||||||
|
|
||||||
The `AsyncPipe` is also stateful.
|
<div class="alert is-helpful">
|
||||||
The pipe maintains a subscription to the input `Observable` and
|
|
||||||
keeps delivering values from that `Observable` as they arrive.
|
|
||||||
|
|
||||||
This next example binds an `Observable` of message strings
|
For details and examples of observables, see the [Observables Overview](/guide/observables#using-observables-to-pass-values "Using observables to pass values"").
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
Use the built-in [`AsyncPipe`](/api/common/AsyncPipe "API description of AsyncPipe") to accept an observable as input and subscribe to the input automatically.
|
||||||
|
Without this pipe, your component code would have to subscribe to the observable to consume its values, extract the resolved values, expose them for binding, and unsubscribe when the observable is destroyed in order to prevent memory leaks. `AsyncPipe` is an impure pipe that saves boilerplate code in your component to maintain the subscription and keep delivering values from that observable as they arrive.
|
||||||
|
|
||||||
|
The following code example binds an observable of message strings
|
||||||
(`message$`) to a view with the `async` pipe.
|
(`message$`) to a view with the `async` pipe.
|
||||||
|
|
||||||
|
|
||||||
<code-example path="pipes/src/app/hero-async-message.component.ts" header="src/app/hero-async-message.component.ts">
|
<code-example path="pipes/src/app/hero-async-message.component.ts" header="src/app/hero-async-message.component.ts">
|
||||||
|
|
||||||
</code-example>
|
</code-example>
|
||||||
|
|
||||||
|
{@a no-filter-pipe}
|
||||||
|
|
||||||
|
## Caching HTTP requests
|
||||||
|
|
||||||
The Async pipe saves boilerplate in the component code.
|
To [communicate with backend services using HTTP](/guide/http "Communicating with backend services using HTTP"), the `HttpClient` service uses observables and offers the `HTTPClient.get()` method to fetch data from a server.
|
||||||
The component doesn't have to subscribe to the async data source,
|
The aynchronous method sends an HTTP request, and returns an observable that emits the requested data for the response.
|
||||||
extract the resolved values and expose them for binding,
|
|
||||||
and have to unsubscribe when it's destroyed
|
|
||||||
(a potent source of memory leaks).
|
|
||||||
|
|
||||||
<h3 class="no-toc">An impure caching pipe</h3>
|
As shown in the previous section, you can use the impure `AsyncPipe` to accept an observable as input and subscribe to the input automatically.
|
||||||
|
You can also create an impure pipe to make and cache an HTTP request.
|
||||||
|
|
||||||
Write one more impure pipe, a pipe that makes an HTTP request.
|
Impure pipes are called whenever change detection runs for a component, which could be every few milliseconds for `CheckAlways`.
|
||||||
|
To avoid performance problems, call the server only when the requested URL changes, as shown in the following example, and use the pipe to cache the server response.
|
||||||
|
The tabs show the following:
|
||||||
|
|
||||||
Remember that impure pipes are called every few milliseconds.
|
* The `fetch` pipe (`fetch-json.pipe.ts`).
|
||||||
If you're not careful, this pipe will punish the server with requests.
|
* A harness component (`hero-list.component.ts`) for demonstrating the request, using a template that defines two bindings to the pipe requesting the heroes from the `heroes.json` file. The second binding chains the `fetch` pipe with the built-in `JsonPipe` to display the same hero data in JSON format.
|
||||||
|
|
||||||
In the following code, the pipe only calls the server when the requested URL changes and it caches the server response.
|
<code-tabs>
|
||||||
The code uses the [Angular http](guide/http) client to retrieve data:
|
<code-pane
|
||||||
|
header="src/app/fetch-json.pipe.ts"
|
||||||
|
path="pipes/src/app/fetch-json.pipe.ts">
|
||||||
|
</code-pane>
|
||||||
|
<code-pane
|
||||||
|
header="src/app/hero-list.component.ts"
|
||||||
|
path="pipes/src/app/hero-list.component.ts">
|
||||||
|
</code-pane>
|
||||||
|
</code-tabs>
|
||||||
|
|
||||||
|
In the above example, a breakpoint on the pipe's request for data shows the following:
|
||||||
|
|
||||||
<code-example path="pipes/src/app/fetch-json.pipe.ts" header="src/app/fetch-json.pipe.ts">
|
* Each binding gets its own pipe instance.
|
||||||
|
* Each pipe instance caches its own URL and data and calls the server only once.
|
||||||
</code-example>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Now demonstrate it in a harness component whose template defines two bindings to this pipe,
|
|
||||||
both requesting the heroes from the `heroes.json` file.
|
|
||||||
|
|
||||||
|
|
||||||
<code-example path="pipes/src/app/hero-list.component.ts" header="src/app/hero-list.component.ts">
|
|
||||||
|
|
||||||
</code-example>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
The component renders as the following:
|
|
||||||
|
|
||||||
|
The `fetch` and `fetch-json` pipes display the heroes as shown in Figure 5.
|
||||||
|
|
||||||
<div class="lightbox">
|
<div class="lightbox">
|
||||||
<img src='generated/images/guide/pipes/hero-list.png' alt="Hero List">
|
<img src='generated/images/guide/pipes/hero-list.png' alt="Hero List">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
**Figure 5.** The `fetch` and `fetch-json` pipes displaying the heroes
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
A breakpoint on the pipe's request for data shows the following:
|
The built-in [JsonPipe](api/common/JsonPipe "API description for JsonPipe") provides a way to diagnose a mysteriously failing data binding or to inspect an object for future binding.
|
||||||
|
|
||||||
* Each binding gets its own pipe instance.
|
|
||||||
* Each pipe instance caches its own URL and data.
|
|
||||||
* Each pipe instance only calls the server once.
|
|
||||||
|
|
||||||
<h3 class="no-toc"><i>JsonPipe</i></h3>
|
|
||||||
|
|
||||||
In the previous code sample, the second `fetch` pipe binding demonstrates more pipe chaining.
|
|
||||||
It displays the same hero data in JSON format by chaining through to the built-in `JsonPipe`.
|
|
||||||
|
|
||||||
|
|
||||||
<div class="callout is-helpful">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<header>
|
|
||||||
Debugging with the json pipe
|
|
||||||
</header>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
The [JsonPipe](api/common/JsonPipe)
|
|
||||||
provides an easy way to diagnose a mysteriously failing data binding or
|
|
||||||
inspect an object for future binding.
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{@a pure-pipe-pure-fn}
|
|
||||||
|
|
||||||
|
|
||||||
<h3 class="no-toc">Pure pipes and pure functions</h3>
|
|
||||||
|
|
||||||
A pure pipe uses pure functions.
|
|
||||||
Pure functions process inputs and return values without detectable side effects.
|
|
||||||
Given the same input, they should always return the same output.
|
|
||||||
|
|
||||||
The pipes discussed earlier in this page are implemented with pure functions.
|
|
||||||
The built-in `DatePipe` is a pure pipe with a pure function implementation.
|
|
||||||
So are the `ExponentialStrengthPipe` and `FlyingHeroesPipe`.
|
|
||||||
A few steps back, you reviewed the `FlyingHeroesImpurePipe`—an impure pipe with a pure function.
|
|
||||||
|
|
||||||
But always implement a *pure pipe* with a *pure function*.
|
|
||||||
Otherwise, you'll see many console errors regarding expressions that changed after they were checked.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Next steps
|
|
||||||
|
|
||||||
Pipes are a great way to encapsulate and share common display-value
|
|
||||||
transformations. Use them like styles, dropping them
|
|
||||||
into your template's expressions to enrich the appeal and usability
|
|
||||||
of your views.
|
|
||||||
|
|
||||||
Explore Angular's inventory of built-in pipes in the [API Reference](api?type=pipe).
|
|
||||||
Try writing a custom pipe and perhaps contributing it to the community.
|
|
||||||
|
|
||||||
|
|
||||||
{@a no-filter-pipe}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Appendix: No *FilterPipe* or *OrderByPipe*
|
|
||||||
|
|
||||||
Angular doesn't provide pipes for filtering or sorting lists.
|
|
||||||
Developers familiar with AngularJS know these as `filter` and `orderBy`.
|
|
||||||
There are no equivalents in Angular.
|
|
||||||
|
|
||||||
This isn't an oversight. Angular doesn't offer such pipes because
|
|
||||||
they perform poorly and prevent aggressive minification.
|
|
||||||
Both `filter` and `orderBy` require parameters that reference object properties.
|
|
||||||
Earlier in this page, you learned that such pipes must be [impure](guide/pipes#pure-and-impure-pipes) and that
|
|
||||||
Angular calls impure pipes in almost every change-detection cycle.
|
|
||||||
|
|
||||||
Filtering and especially sorting are expensive operations.
|
|
||||||
The user experience can degrade severely for even moderate-sized lists when Angular calls these pipe methods many times per second.
|
|
||||||
`filter` and `orderBy` have often been abused in AngularJS apps, leading to complaints that Angular itself is slow.
|
|
||||||
That charge is fair in the indirect sense that AngularJS prepared this performance trap
|
|
||||||
by offering `filter` and `orderBy` in the first place.
|
|
||||||
|
|
||||||
The minification hazard is also compelling, if less obvious. Imagine a sorting pipe applied to a list of heroes.
|
|
||||||
The list might be sorted by hero `name` and `planet` of origin properties in the following way:
|
|
||||||
|
|
||||||
<code-example language="html">
|
|
||||||
<!-- NOT REAL CODE! -->
|
|
||||||
<div *ngFor="let hero of heroes | orderBy:'name,planet'"></div>
|
|
||||||
</code-example>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
You identify the sort fields by text strings, expecting the pipe to reference a property value by indexing
|
|
||||||
(such as `hero['name']`).
|
|
||||||
Unfortunately, aggressive minification manipulates the `Hero` property names so that `Hero.name` and `Hero.planet`
|
|
||||||
become something like `Hero.a` and `Hero.b`. Clearly `hero['name']` doesn't work.
|
|
||||||
|
|
||||||
While some may not care to minify this aggressively,
|
|
||||||
the Angular product shouldn't prevent anyone from minifying aggressively.
|
|
||||||
Therefore, the Angular team decided that everything Angular provides will minify safely.
|
|
||||||
|
|
||||||
The Angular team and many experienced Angular developers strongly recommend moving
|
|
||||||
filtering and sorting logic into the component itself.
|
|
||||||
The component can expose a `filteredHeroes` or `sortedHeroes` property and take control
|
|
||||||
over when and how often to execute the supporting logic.
|
|
||||||
Any capabilities that you would have put in a pipe and shared across the app can be
|
|
||||||
written in a filtering/sorting service and injected into the component.
|
|
||||||
|
|
||||||
If these performance and minification considerations don't apply to you, you can always create your own such pipes
|
|
||||||
(similar to the [FlyingHeroesPipe](guide/pipes#impure-flying-heroes)) or find them in the community.
|
|
||||||
|
@ -52,6 +52,14 @@ Any component created within a lazy loaded module’s context, such as by router
|
|||||||
|
|
||||||
Though you can provide services by lazy loading modules, not all services can be lazy loaded. For instance, some modules only work in the root module, such as the Router. The Router works with the global location object in the browser.
|
Though you can provide services by lazy loading modules, not all services can be lazy loaded. For instance, some modules only work in the root module, such as the Router. The Router works with the global location object in the browser.
|
||||||
|
|
||||||
|
As of Angular version 9, you can provide a new instance of a service with each lazy loaded module. The following code adds this functionality to `UserService`.
|
||||||
|
|
||||||
|
<code-example path="providers/src/app/user.service.2.ts" header="src/app/user.service.ts"></code-example>
|
||||||
|
|
||||||
|
With `providedIn: 'any'`, all eagerly loaded modules share a singleton instance; however, lazy loaded modules each get their own unique instance, as shown in the following diagram.
|
||||||
|
|
||||||
|
<img src="generated/images/guide/providers/any-provider.svg" alt="any-provider-scope" class="left">
|
||||||
|
|
||||||
|
|
||||||
## Limiting provider scope with components
|
## Limiting provider scope with components
|
||||||
|
|
||||||
|
@ -101,6 +101,7 @@ The following table provides the status for Angular versions under support.
|
|||||||
|
|
||||||
Version | Status | Released | Active Ends | LTS Ends
|
Version | Status | Released | Active Ends | LTS Ends
|
||||||
------- | ------ | ------------ | ------------ | ------------
|
------- | ------ | ------------ | ------------ | ------------
|
||||||
|
^10.0.0 | Active | Jun 24, 2020 | Dec 24, 2020 | Dec 24, 2021
|
||||||
^9.0.0 | Active | Feb 06, 2020 | Aug 06, 2020 | Aug 06, 2021
|
^9.0.0 | Active | Feb 06, 2020 | Aug 06, 2020 | Aug 06, 2021
|
||||||
^8.0.0 | LTS | May 28, 2019 | Nov 28, 2019 | Nov 28, 2020
|
^8.0.0 | LTS | May 28, 2019 | Nov 28, 2019 | Nov 28, 2020
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ Let's assume that we are routing from the *Home => About*.
|
|||||||
|
|
||||||
The animation code does the following after styling the views:
|
The animation code does the following after styling the views:
|
||||||
|
|
||||||
* `query(':enter style({ left: '-100%'})` matches the view that is added and hides the newly added view by positioning it to the far left.
|
* `query(':enter', style({ left: '-100%' }))` matches the view that is added and hides the newly added view by positioning it to the far left.
|
||||||
* Calls `animateChild()` on the view that is leaving, to run its child animations.
|
* Calls `animateChild()` on the view that is leaving, to run its child animations.
|
||||||
* Uses `group()` function to make the inner animations run in parallel.
|
* Uses `group()` function to make the inner animations run in parallel.
|
||||||
* Within the `group()` function:
|
* Within the `group()` function:
|
||||||
|
2893
aio/content/guide/router-tutorial-toh.md
Normal file
2893
aio/content/guide/router-tutorial-toh.md
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
|||||||
# Schematics for libraries
|
# Schematics for libraries
|
||||||
|
|
||||||
When you create an Angular library, you can provide and package it with schematics that integrate it with the Angular CLI.
|
When you create an Angular library, you can provide and package it with schematics that integrate it with the Angular CLI.
|
||||||
With your schematics, your users can use `ng add` to install an initial version of your library,
|
With your schematics, your users can use `ng add` to install an initial version of your library,
|
||||||
`ng generate` to create artifacts defined in your library, and `ng update` to adjust their project for a new version of your library that introduces breaking changes.
|
`ng generate` to create artifacts defined in your library, and `ng update` to adjust their project for a new version of your library that introduces breaking changes.
|
||||||
|
|
||||||
All three types of schematics can be part of a collection that you package with your library.
|
All three types of schematics can be part of a collection that you package with your library.
|
||||||
@ -115,10 +115,10 @@ When you add a schematic to the collection, you have to point to it in the colle
|
|||||||
<code-example header="projects/my-lib/schematics/my-service/schema.json (Schematic JSON Schema)" path="schematics-for-libraries/projects/my-lib/schematics/my-service/schema.json">
|
<code-example header="projects/my-lib/schematics/my-service/schema.json (Schematic JSON Schema)" path="schematics-for-libraries/projects/my-lib/schematics/my-service/schema.json">
|
||||||
</code-example>
|
</code-example>
|
||||||
|
|
||||||
* *id* : A unique id for the schema in the collection.
|
* *id*: A unique id for the schema in the collection.
|
||||||
* *title* : A human-readable description of the schema.
|
* *title*: A human-readable description of the schema.
|
||||||
* *type* : A descriptor for the type provided by the properties.
|
* *type*: A descriptor for the type provided by the properties.
|
||||||
* *properties* : An object that defines the available options for the schematic.
|
* *properties*: An object that defines the available options for the schematic.
|
||||||
|
|
||||||
Each option associates key with a type, description, and optional alias.
|
Each option associates key with a type, description, and optional alias.
|
||||||
The type defines the shape of the value you expect, and the description is displayed when the user requests usage help for your schematic.
|
The type defines the shape of the value you expect, and the description is displayed when the user requests usage help for your schematic.
|
||||||
@ -130,9 +130,9 @@ When you add a schematic to the collection, you have to point to it in the colle
|
|||||||
<code-example header="projects/my-lib/schematics/my-service/schema.ts (Schematic Interface)" path="schematics-for-libraries/projects/my-lib/schematics/my-service/schema.ts">
|
<code-example header="projects/my-lib/schematics/my-service/schema.ts (Schematic Interface)" path="schematics-for-libraries/projects/my-lib/schematics/my-service/schema.ts">
|
||||||
</code-example>
|
</code-example>
|
||||||
|
|
||||||
* *name* : The name you want to provide for the created service.
|
* *name*: The name you want to provide for the created service.
|
||||||
* *path* : Overrides the path provided to the schematic. The default path value is based on the current working directory.
|
* *path*: Overrides the path provided to the schematic. The default path value is based on the current working directory.
|
||||||
* *project* : Provides a specific project to run the schematic on. In the schematic, you can provide a default if the option is not provided by the user.
|
* *project*: Provides a specific project to run the schematic on. In the schematic, you can provide a default if the option is not provided by the user.
|
||||||
|
|
||||||
### Add template files
|
### Add template files
|
||||||
|
|
||||||
@ -169,10 +169,9 @@ The Schematics framework provides a file templating system, which supports both
|
|||||||
The system operates on placeholders defined inside files or paths that loaded in the input `Tree`.
|
The system operates on placeholders defined inside files or paths that loaded in the input `Tree`.
|
||||||
It fills these in using values passed into the `Rule`.
|
It fills these in using values passed into the `Rule`.
|
||||||
|
|
||||||
For details of these data structure and syntax, see the [Schematics README](https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/schematics/README.md).
|
For details of these data structures and syntax, see the [Schematics README](https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/schematics/README.md).
|
||||||
|
|
||||||
|
1. Create the main file `index.ts` and add the source code for your schematic factory function.
|
||||||
1. Create the main file, `index.ts` and add the source code for your schematic factory function.
|
|
||||||
|
|
||||||
1. First, import the schematics definitions you will need. The Schematics framework offers many utility functions to create and use rules when running a schematic.
|
1. First, import the schematics definitions you will need. The Schematics framework offers many utility functions to create and use rules when running a schematic.
|
||||||
|
|
||||||
@ -271,7 +270,6 @@ For more information about rules and utility methods, see [Provided Rules](https
|
|||||||
|
|
||||||
After you build your library and schematics, you can install the schematics collection to run against your project. The steps below show you how to generate a service using the schematic you created above.
|
After you build your library and schematics, you can install the schematics collection to run against your project. The steps below show you how to generate a service using the schematic you created above.
|
||||||
|
|
||||||
|
|
||||||
### Build your library and schematics
|
### Build your library and schematics
|
||||||
|
|
||||||
From the root of your workspace, run the `ng build` command for your library.
|
From the root of your workspace, run the `ng build` command for your library.
|
||||||
|
@ -31,28 +31,27 @@ You can use these events to notify the user of a pending update or to refresh th
|
|||||||
|
|
||||||
### Checking for updates
|
### Checking for updates
|
||||||
|
|
||||||
It's possible to ask the service worker to check if any updates have been deployed to the server. You might choose to do this if you have a site that changes frequently or want updates to happen on a schedule.
|
It's possible to ask the service worker to check if any updates have been deployed to the server.
|
||||||
|
The service worker checks for updates during initialization and on each navigation request—that is, when the user navigates from a different address to your app.
|
||||||
|
However, you might choose to manually check for updates if you have a site that changes frequently or want updates to happen on a schedule.
|
||||||
|
|
||||||
Do this with the `checkForUpdate()` method:
|
Do this with the `checkForUpdate()` method:
|
||||||
|
|
||||||
<code-example path="service-worker-getting-started/src/app/check-for-update.service.ts" header="check-for-update.service.ts"></code-example>
|
<code-example path="service-worker-getting-started/src/app/check-for-update.service.ts" header="check-for-update.service.ts"></code-example>
|
||||||
|
|
||||||
|
|
||||||
This method returns a `Promise` which indicates that the update check has completed successfully, though it does not indicate whether an update was discovered as a result of the check. Even if one is found, the service worker must still successfully download the changed files, which can fail. If successful, the `available` event will indicate availability of a new version of the app.
|
This method returns a `Promise` which indicates that the update check has completed successfully, though it does not indicate whether an update was discovered as a result of the check. Even if one is found, the service worker must still successfully download the changed files, which can fail. If successful, the `available` event will indicate availability of a new version of the app.
|
||||||
|
|
||||||
<div class="alert is-important">
|
<div class="alert is-important">
|
||||||
|
|
||||||
In order to avoid negatively affecting the initial rendering, `ServiceWorkerModule` will by default
|
In order to avoid negatively affecting the initial rendering of the page, `ServiceWorkerModule` waits for up to 30 seconds by default for the app to stabilize, before registering the ServiceWorker script.
|
||||||
wait for the app to stabilize, before registering the ServiceWorker script. Constantly polling for
|
Constantly polling for updates, for example, with [setInterval()](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval) or RxJS' [interval()](https://rxjs.dev/api/index/function/interval), will prevent the app from stabilizing and the ServiceWorker script will not be registered with the browser until the 30 seconds upper limit is reached.
|
||||||
updates, e.g. with `interval()`, will prevent the app from stabilizing and the ServiceWorker
|
|
||||||
script will never be registered with the browser.
|
|
||||||
|
|
||||||
You can avoid that by waiting for the app to stabilize first, before starting to poll for updates
|
|
||||||
(as shown in the example above).
|
|
||||||
|
|
||||||
Note that this is true for any kind of polling done by your application.
|
Note that this is true for any kind of polling done by your application.
|
||||||
Check the {@link ApplicationRef#isStable isStable} documentation for more information.
|
Check the {@link ApplicationRef#isStable isStable} documentation for more information.
|
||||||
|
|
||||||
|
You can avoid that delay by waiting for the app to stabilize first, before starting to poll for updates, as shown in the example above.
|
||||||
|
Alternatively, you might want to define a different {@link SwRegistrationOptions#registrationStrategy registration strategy} for the ServiceWorker.
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
### Forcing update activation
|
### Forcing update activation
|
||||||
@ -61,7 +60,12 @@ If the current tab needs to be updated to the latest app version immediately, it
|
|||||||
|
|
||||||
<code-example path="service-worker-getting-started/src/app/prompt-update.service.ts" header="prompt-update.service.ts" region="sw-activate"></code-example>
|
<code-example path="service-worker-getting-started/src/app/prompt-update.service.ts" header="prompt-update.service.ts" region="sw-activate"></code-example>
|
||||||
|
|
||||||
Doing this could break lazy-loading in currently running apps, especially if the lazy-loaded chunks use filenames with hashes, which change every version.
|
<div class="alert is-important">
|
||||||
|
|
||||||
|
Calling `activateUpdate()` without reloading the page could break lazy-loading in a currently running app, especially if the lazy-loaded chunks use filenames with hashes, which change every version.
|
||||||
|
Therefore, it is recommended to reload the page once the promise returned by `activateUpdate()` is resolved.
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
## More on Angular service workers
|
## More on Angular service workers
|
||||||
|
|
||||||
|
@ -25,49 +25,48 @@ To use the Angular framework, you should be familiar with the following:
|
|||||||
|
|
||||||
Knowledge of [TypeScript](https://www.typescriptlang.org/) is helpful, but not required.
|
Knowledge of [TypeScript](https://www.typescriptlang.org/) is helpful, but not required.
|
||||||
|
|
||||||
|
To install Angular on your local system, you need the following:
|
||||||
|
|
||||||
{@a nodejs}
|
{@a nodejs}
|
||||||
### Node.js
|
|
||||||
|
|
||||||
Make sure your development environment includes `Node.js®` and an npm package manager.
|
* **Node.js**
|
||||||
|
|
||||||
|
Angular requires a [current, active LTS, or maintenance LTS](https://nodejs.org/about/releases) version of Node.js.
|
||||||
|
|
||||||
Angular requires a [current, active LTS, or maintenance LTS](https://nodejs.org/about/releases/) version of `Node.js`. See the `engines` key for the specific version requirements in our [package.json](https://unpkg.com/@angular/cli/package.json).
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
* To check your version, run `node -v` in a terminal/console window.
|
For information about specific version requirements, see the `engines` key in the [package.json](https://unpkg.com/@angular/cli/package.json) file.
|
||||||
|
|
||||||
* To get `Node.js`, go to [nodejs.org](https://nodejs.org "Nodejs.org").
|
</div>
|
||||||
|
|
||||||
|
For more information on installing Node.js, see [nodejs.org](http://nodejs.org "Nodejs.org").
|
||||||
|
If you are unsure what version of Node.js runs on your system, run `node -v` in a terminal window.
|
||||||
|
|
||||||
{@a npm}
|
{@a npm}
|
||||||
### npm package manager
|
|
||||||
|
|
||||||
Angular, the Angular CLI, and Angular apps depend on features and functionality provided by libraries that are available as [npm packages](https://docs.npmjs.com/getting-started/what-is-npm). To download and install npm packages, you must have an npm package manager.
|
* **npm package manager**
|
||||||
|
|
||||||
This setup guide uses the [npm client](https://docs.npmjs.com/cli/install) command line interface, which is installed with `Node.js` by default.
|
Angular, the Angular CLI, and Angular applications depend on [npm packages](https://docs.npmjs.com/getting-started/what-is-npm) for many features and functions.
|
||||||
|
To download and install npm packages, you need an npm package manager.
|
||||||
To check that you have the npm client installed, run `npm -v` in a terminal/console window.
|
This guide uses the [npm client](https://docs.npmjs.com/cli/install) command line interface, which is installed with `Node.js` by default.
|
||||||
|
To check that you have the npm client installed, run `npm -v` in a terminal window.
|
||||||
|
|
||||||
|
|
||||||
{@a install-cli}
|
{@a install-cli}
|
||||||
|
|
||||||
## Step 1: Install the Angular CLI
|
## Install the Angular CLI
|
||||||
|
|
||||||
You use the Angular CLI
|
You use the Angular CLI to create projects, generate application and library code, and perform a variety of ongoing development tasks such as testing, bundling, and deployment.
|
||||||
to create projects, generate application and library code, and perform a variety of ongoing development tasks such as testing, bundling, and deployment.
|
|
||||||
|
|
||||||
Install the Angular CLI globally.
|
|
||||||
|
|
||||||
To install the CLI using `npm`, open a terminal/console window and enter the following command:
|
|
||||||
|
|
||||||
|
To install the Angular CLI, open a terminal window and run the following command:
|
||||||
|
|
||||||
<code-example language="sh" class="code-shell">
|
<code-example language="sh" class="code-shell">
|
||||||
npm install -g @angular/cli
|
npm install -g @angular/cli
|
||||||
|
|
||||||
</code-example>
|
</code-example>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{@a create-proj}
|
{@a create-proj}
|
||||||
|
|
||||||
## Step 2: Create a workspace and initial application
|
## Create a workspace and initial application
|
||||||
|
|
||||||
You develop apps in the context of an Angular [**workspace**](guide/glossary#workspace).
|
You develop apps in the context of an Angular [**workspace**](guide/glossary#workspace).
|
||||||
|
|
||||||
@ -86,16 +85,22 @@ The Angular CLI installs the necessary Angular npm packages and other dependenci
|
|||||||
|
|
||||||
The CLI creates a new workspace and a simple Welcome app, ready to run.
|
The CLI creates a new workspace and a simple Welcome app, ready to run.
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
You also have the option to use Angular's strict mode, which can help you write better, more maintainable code.
|
||||||
|
For more information, see [Strict mode](/guide/strict-mode).
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
{@a serve}
|
{@a serve}
|
||||||
|
|
||||||
## Step 3: Run the application
|
## Run the application
|
||||||
|
|
||||||
The Angular CLI includes a server, so that you can easily build and serve your app locally.
|
The Angular CLI includes a server, so that you can build and serve your app locally.
|
||||||
|
|
||||||
1. Go to the workspace folder (`my-app`).
|
1. Navigate to the workspace folder, such as `my-app`.
|
||||||
|
|
||||||
1. Launch the server by using the CLI command `ng serve`, with the `--open` option.
|
1. Run the following command:
|
||||||
|
|
||||||
<code-example language="sh" class="code-shell">
|
<code-example language="sh" class="code-shell">
|
||||||
cd my-app
|
cd my-app
|
||||||
@ -108,7 +113,7 @@ and rebuilds the app as you make changes to those files.
|
|||||||
The `--open` (or just `-o`) option automatically opens your browser
|
The `--open` (or just `-o`) option automatically opens your browser
|
||||||
to `http://localhost:4200/`.
|
to `http://localhost:4200/`.
|
||||||
|
|
||||||
You will see:
|
If your installation and setup was successful, you should see a page similar to the following.
|
||||||
|
|
||||||
|
|
||||||
<div class="lightbox">
|
<div class="lightbox">
|
||||||
|
46
aio/content/guide/strict-mode.md
Normal file
46
aio/content/guide/strict-mode.md
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
# Strict mode
|
||||||
|
|
||||||
|
When you create a new workspace or a project you have an option to create them in a strict mode using the `--strict` flag.
|
||||||
|
|
||||||
|
Enabling this flag initializes your new workspace or project with a few new settings that improve maintainability, help you catch bugs ahead of time, and allow the CLI to perform advanced optimizations on your application.
|
||||||
|
Additionally, applications that use these stricter settings are easier to statically analyze, which can help the `ng update` command refactor code more safely and precisely when you are updating to future versions of Angular.
|
||||||
|
|
||||||
|
Specifically, the `strict` flag does the following:
|
||||||
|
|
||||||
|
* Enables [`strict` mode in TypeScript](https://www.staging-typescript.org/tsconfig#strict), as well as other strictness flags recommended by the TypeScript team. Specifically, `forceConsistentCasingInFileNames`, `noImplicitReturns`, `noFallthroughCasesInSwitch`.
|
||||||
|
* Turns on strict Angular compiler flags [`strictTemplates`](guide/angular-compiler-options#stricttemplates) and [`strictInjectionParameters`](guide/angular-compiler-options#strictinjectionparameters)
|
||||||
|
* [Bundle size budgets](guide/build#configuring-size-budgets) have been reduced by ~75%
|
||||||
|
* Turns on [`no-any` tslint rule](https://palantir.github.io/tslint/rules/no-any/) to prevent declarations of type `any`
|
||||||
|
* [Marks your application as side-effect free](https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free) to enable more advanced tree-shaking
|
||||||
|
|
||||||
|
You can apply these settings at the workspace and project level.
|
||||||
|
|
||||||
|
To create a new workspace and application using the strict mode, run the following command:
|
||||||
|
|
||||||
|
<code-example language="sh" class="code-shell">
|
||||||
|
|
||||||
|
ng new [project-name] --strict
|
||||||
|
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
To create a new application in the strict mode within an existing non-strict workspace, run the following command:
|
||||||
|
|
||||||
|
<code-example language="sh" class="code-shell">
|
||||||
|
|
||||||
|
ng generate application [project-name] --strict
|
||||||
|
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
{@a side-effect}
|
||||||
|
|
||||||
|
### Non-local side effects in applications
|
||||||
|
|
||||||
|
When you create projects and workspaces using the `strict` mode, you'll notice an additional `package.json` file, located in `src/app/` directory.
|
||||||
|
This file informs tools and bundlers that the code under this directory is free of non-local side effects. Non-local side effects in the application code are not common and using them is not considered a good coding pattern.
|
||||||
|
More importantly, code with these types of side effects cannot be optimized, resulting in increased bundle sizes and applications that load more slowly.
|
||||||
|
|
||||||
|
If you need more information, the following links may be helpful.
|
||||||
|
|
||||||
|
* [Tree-shaking](https://webpack.js.org/guides/tree-shaking/)
|
||||||
|
* [Dealing with side effects and pure functions in JavaScript](https://dev.to/vonheikemen/dealing-with-side-effects-and-pure-functions-in-javascript-16mg)
|
||||||
|
* [How to deal with dirty side effects in your pure function JavaScript](https://jrsinclair.com/articles/2018/how-to-deal-with-dirty-side-effects-in-your-pure-functional-javascript/)
|
@ -821,8 +821,8 @@ content harmlessly. The following is the browser output
|
|||||||
of the `evilTitle` examples.
|
of the `evilTitle` examples.
|
||||||
|
|
||||||
<code-example language="bash">
|
<code-example language="bash">
|
||||||
"Template <script>alert("evil never sleeps")</script> Syntax" is the interpolated evil title.
|
"Template <script>alert("evil never sleeps")</script> Syntax" is the interpolated evil title.
|
||||||
"Template alert("evil never sleeps")Syntax" is the property bound evil title.
|
"Template Syntax" is the property bound evil title.
|
||||||
</code-example>
|
</code-example>
|
||||||
|
|
||||||
<hr/>
|
<hr/>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
## Overview of template type checking
|
## Overview of template type checking
|
||||||
|
|
||||||
Just as TypeScript catches type errors in your code, Angular checks the expressions and bindings within the templates of your application and can report any type errors it finds.
|
Just as TypeScript catches type errors in your code, Angular checks the expressions and bindings within the templates of your application and can report any type errors it finds.
|
||||||
Angular currently has three modes of doing this, depending on the value of the `fullTemplateTypeCheck` and `strictTemplates` flags in the [TypeScript configuration file](guide/typescript-configuration), `tsconfig.json`.
|
Angular currently has three modes of doing this, depending on the value of the `fullTemplateTypeCheck` and `strictTemplates` flags in the [TypeScript configuration file](guide/typescript-configuration).
|
||||||
|
|
||||||
### Basic mode
|
### Basic mode
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ There can also be false positives when the typings of an Angular library are eit
|
|||||||
In case of a false positive like these, there are a few options:
|
In case of a false positive like these, there are a few options:
|
||||||
|
|
||||||
* Use the [`$any()` type-cast function](guide/template-syntax#any-type-cast-function) in certain contexts to opt out of type-checking for a part of the expression.
|
* Use the [`$any()` type-cast function](guide/template-syntax#any-type-cast-function) in certain contexts to opt out of type-checking for a part of the expression.
|
||||||
* You can disable strict checks entirely by setting `strictTemplates: false` in the application's TypeScript configuration file, `tsconfig.json`.
|
* You can disable strict checks entirely by setting `strictTemplates: false` in the application's TypeScript configuration file.
|
||||||
* You can disable certain type-checking operations individually, while maintaining strictness in other aspects, by setting a _strictness flag_ to `false`.
|
* You can disable certain type-checking operations individually, while maintaining strictness in other aspects, by setting a _strictness flag_ to `false`.
|
||||||
* If you want to use `strictTemplates` and `strictNullChecks` together, you can opt out of strict null type checking specifically for input bindings via `strictNullInputTypes`.
|
* If you want to use `strictTemplates` and `strictNullChecks` together, you can opt out of strict null type checking specifically for input bindings via `strictNullInputTypes`.
|
||||||
|
|
||||||
|
28
aio/content/guide/test-debugging.md
Normal file
28
aio/content/guide/test-debugging.md
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# Debugging tests
|
||||||
|
|
||||||
|
If your tests aren't working as you expect them to, you can inspect and debug them in the browser.
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
For the sample app that the testing guides describe, see the <live-example name="testing" embedded-style noDownload>sample app</live-example>.
|
||||||
|
|
||||||
|
For the tests features in the testing guides, see <live-example name="testing" stackblitz="specs" noDownload>tests</live-example>.
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
Debug specs in the browser in the same way that you debug an application.
|
||||||
|
|
||||||
|
1. Reveal the Karma browser window. See [Set up testing](guide/testing#set-up-testing) if you need help with this step.
|
||||||
|
1. Click the **DEBUG** button; it opens a new browser tab and re-runs the tests.
|
||||||
|
1. Open the browser's “Developer Tools” (`Ctrl-Shift-I` on Windows; `Command-Option-I` in macOS).
|
||||||
|
1. Pick the "sources" section.
|
||||||
|
1. Open the `1st.spec.ts` test file (Control/Command-P, then start typing the name of the file).
|
||||||
|
1. Set a breakpoint in the test.
|
||||||
|
1. Refresh the browser, and it stops at the breakpoint.
|
||||||
|
|
||||||
|
<div class="lightbox">
|
||||||
|
<img src='generated/images/guide/testing/karma-1st-spec-debug.png' alt="Karma debugging">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
78
aio/content/guide/testing-attribute-directives.md
Normal file
78
aio/content/guide/testing-attribute-directives.md
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
|
||||||
|
{@a attribute-directive}
|
||||||
|
|
||||||
|
# Testing Attribute Directives
|
||||||
|
|
||||||
|
An _attribute directive_ modifies the behavior of an element, component or another directive.
|
||||||
|
Its name reflects the way the directive is applied: as an attribute on a host element.
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
For the sample app that the testing guides describe, see the <live-example name="testing" embedded-style noDownload>sample app</live-example>.
|
||||||
|
|
||||||
|
For the tests features in the testing guides, see <live-example name="testing" stackblitz="specs" noDownload>tests</live-example>.
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
## Testing the `HighlightDirective`
|
||||||
|
|
||||||
|
The sample application's `HighlightDirective` sets the background color of an element
|
||||||
|
based on either a data bound color or a default color (lightgray).
|
||||||
|
It also sets a custom property of the element (`customProperty`) to `true`
|
||||||
|
for no reason other than to show that it can.
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/shared/highlight.directive.ts" header="app/shared/highlight.directive.ts"></code-example>
|
||||||
|
|
||||||
|
It's used throughout the application, perhaps most simply in the `AboutComponent`:
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/about/about.component.ts" header="app/about/about.component.ts"></code-example>
|
||||||
|
|
||||||
|
Testing the specific use of the `HighlightDirective` within the `AboutComponent` requires only the techniques explored in the ["Nested component tests"](guide/testing-components-scenarios#nested-component-tests) section of [Component testing scenarios](guide/testing-components-scenarios).
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/about/about.component.spec.ts" region="tests" header="app/about/about.component.spec.ts"></code-example>
|
||||||
|
|
||||||
|
However, testing a single use case is unlikely to explore the full range of a directive's capabilities.
|
||||||
|
Finding and testing all components that use the directive is tedious, brittle, and almost as unlikely to afford full coverage.
|
||||||
|
|
||||||
|
_Class-only tests_ might be helpful,
|
||||||
|
but attribute directives like this one tend to manipulate the DOM.
|
||||||
|
Isolated unit tests don't touch the DOM and, therefore,
|
||||||
|
do not inspire confidence in the directive's efficacy.
|
||||||
|
|
||||||
|
A better solution is to create an artificial test component that demonstrates all ways to apply the directive.
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/shared/highlight.directive.spec.ts" region="test-component" header="app/shared/highlight.directive.spec.ts (TestComponent)"></code-example>
|
||||||
|
|
||||||
|
<div class="lightbox">
|
||||||
|
<img src='generated/images/guide/testing/highlight-directive-spec.png' alt="HighlightDirective spec in action">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
The `<input>` case binds the `HighlightDirective` to the name of a color value in the input box.
|
||||||
|
The initial value is the word "cyan" which should be the background color of the input box.
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
Here are some tests of this component:
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/shared/highlight.directive.spec.ts" region="selected-tests" header="app/shared/highlight.directive.spec.ts (selected tests)"></code-example>
|
||||||
|
|
||||||
|
A few techniques are noteworthy:
|
||||||
|
|
||||||
|
- The `By.directive` predicate is a great way to get the elements that have this directive _when their element types are unknown_.
|
||||||
|
|
||||||
|
- The <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:not">`:not` pseudo-class</a>
|
||||||
|
in `By.css('h2:not([highlight])')` helps find `<h2>` elements that _do not_ have the directive.
|
||||||
|
`By.css('*:not([highlight])')` finds _any_ element that does not have the directive.
|
||||||
|
|
||||||
|
- `DebugElement.styles` affords access to element styles even in the absence of a real browser, thanks to the `DebugElement` abstraction.
|
||||||
|
But feel free to exploit the `nativeElement` when that seems easier or more clear than the abstraction.
|
||||||
|
|
||||||
|
- Angular adds a directive to the injector of the element to which it is applied.
|
||||||
|
The test for the default color uses the injector of the second `<h2>` to get its `HighlightDirective` instance
|
||||||
|
and its `defaultColor`.
|
||||||
|
|
||||||
|
- `DebugElement.properties` affords access to the artificial custom property that is set by the directive.
|
||||||
|
|
||||||
|
<hr>
|
57
aio/content/guide/testing-code-coverage.md
Normal file
57
aio/content/guide/testing-code-coverage.md
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
{@a code-coverage}
|
||||||
|
|
||||||
|
# Find out how much code you're testing
|
||||||
|
|
||||||
|
The CLI can run unit tests and create code coverage reports.
|
||||||
|
Code coverage reports show you any parts of your code base that may not be properly tested by your unit tests.
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
For the sample app that the testing guides describe, see the <live-example name="testing" embedded-style noDownload>sample app</live-example>.
|
||||||
|
|
||||||
|
For the tests features in the testing guides, see <live-example name="testing" stackblitz="specs" noDownload>tests</live-example>.
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
To generate a coverage report run the following command in the root of your project.
|
||||||
|
|
||||||
|
<code-example language="sh" class="code-shell">
|
||||||
|
ng test --no-watch --code-coverage
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
When the tests are complete, the command creates a new `/coverage` folder in the project. Open the `index.html` file to see a report with your source code and code coverage values.
|
||||||
|
|
||||||
|
If you want to create code-coverage reports every time you test, you can set the following option in the CLI configuration file, `angular.json`:
|
||||||
|
|
||||||
|
```
|
||||||
|
"test": {
|
||||||
|
"options": {
|
||||||
|
"codeCoverage": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Code coverage enforcement
|
||||||
|
|
||||||
|
The code coverage percentages let you estimate how much of your code is tested.
|
||||||
|
If your team decides on a set minimum amount to be unit tested, you can enforce this minimum with the Angular CLI.
|
||||||
|
|
||||||
|
For example, suppose you want the code base to have a minimum of 80% code coverage.
|
||||||
|
To enable this, open the [Karma](https://karma-runner.github.io) test platform configuration file, `karma.conf.js`, and add the following in the `coverageIstanbulReporter:` key.
|
||||||
|
|
||||||
|
```
|
||||||
|
coverageIstanbulReporter: {
|
||||||
|
reports: [ 'html', 'lcovonly' ],
|
||||||
|
fixWebpackSourcePaths: true,
|
||||||
|
thresholds: {
|
||||||
|
statements: 80,
|
||||||
|
lines: 80,
|
||||||
|
branches: 80,
|
||||||
|
functions: 80
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The `thresholds` property causes the tool to enforce a minimum of 80% code coverage when the unit tests are run in the project.
|
||||||
|
|
380
aio/content/guide/testing-components-basics.md
Normal file
380
aio/content/guide/testing-components-basics.md
Normal file
@ -0,0 +1,380 @@
|
|||||||
|
# Basics of testing components
|
||||||
|
|
||||||
|
A component, unlike all other parts of an Angular application,
|
||||||
|
combines an HTML template and a TypeScript class.
|
||||||
|
The component truly is the template and the class _working together_. To adequately test a component, you should test that they work together
|
||||||
|
as intended.
|
||||||
|
|
||||||
|
Such tests require creating the component's host element in the browser DOM,
|
||||||
|
as Angular does, and investigating the component class's interaction with
|
||||||
|
the DOM as described by its template.
|
||||||
|
|
||||||
|
The Angular `TestBed` facilitates this kind of testing as you'll see in the sections below.
|
||||||
|
But in many cases, _testing the component class alone_, without DOM involvement,
|
||||||
|
can validate much of the component's behavior in an easier, more obvious way.
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
For the sample app that the testing guides describe, see the <live-example name="testing" embedded-style noDownload>sample app</live-example>.
|
||||||
|
|
||||||
|
For the tests features in the testing guides, see <live-example name="testing" stackblitz="specs" noDownload>tests</live-example>.
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
{@a component-class-testing}
|
||||||
|
|
||||||
|
## Component class testing
|
||||||
|
|
||||||
|
Test a component class on its own as you would test a service class.
|
||||||
|
|
||||||
|
Component class testing should be kept very clean and simple.
|
||||||
|
It should test only a single unit.
|
||||||
|
At first glance, you should be able to understand
|
||||||
|
what the test is testing.
|
||||||
|
|
||||||
|
Consider this `LightswitchComponent` which toggles a light on and off
|
||||||
|
(represented by an on-screen message) when the user clicks the button.
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/demo/demo.ts"
|
||||||
|
region="LightswitchComp"
|
||||||
|
header="app/demo/demo.ts (LightswitchComp)"></code-example>
|
||||||
|
|
||||||
|
You might decide only to test that the `clicked()` method
|
||||||
|
toggles the light's _on/off_ state and sets the message appropriately.
|
||||||
|
|
||||||
|
This component class has no dependencies. To test these types of classes, follow the same steps as you would for a service that has no dependencies:
|
||||||
|
|
||||||
|
1. Create a component using the new keyword.
|
||||||
|
2. Poke at its API.
|
||||||
|
3. Assert expectations on its public state.
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/demo/demo.spec.ts"
|
||||||
|
region="Lightswitch"
|
||||||
|
header="app/demo/demo.spec.ts (Lightswitch tests)"></code-example>
|
||||||
|
|
||||||
|
Here is the `DashboardHeroComponent` from the _Tour of Heroes_ tutorial.
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/dashboard/dashboard-hero.component.ts"
|
||||||
|
region="class"
|
||||||
|
header="app/dashboard/dashboard-hero.component.ts (component)"></code-example>
|
||||||
|
|
||||||
|
It appears within the template of a parent component,
|
||||||
|
which binds a _hero_ to the `@Input` property and
|
||||||
|
listens for an event raised through the _selected_ `@Output` property.
|
||||||
|
|
||||||
|
You can test that the class code works without creating the `DashboardHeroComponent`
|
||||||
|
or its parent component.
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/dashboard/dashboard-hero.component.spec.ts"
|
||||||
|
region="class-only"
|
||||||
|
header="app/dashboard/dashboard-hero.component.spec.ts (class tests)"></code-example>
|
||||||
|
|
||||||
|
When a component has dependencies, you may wish to use the `TestBed` to both
|
||||||
|
create the component and its dependencies.
|
||||||
|
|
||||||
|
The following `WelcomeComponent` depends on the `UserService` to know the name of the user to greet.
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/welcome/welcome.component.ts"
|
||||||
|
region="class"
|
||||||
|
header="app/welcome/welcome.component.ts"></code-example>
|
||||||
|
|
||||||
|
You might start by creating a mock of the `UserService` that meets the minimum needs of this component.
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/welcome/welcome.component.spec.ts"
|
||||||
|
region="mock-user-service"
|
||||||
|
header="app/welcome/welcome.component.spec.ts (MockUserService)"></code-example>
|
||||||
|
|
||||||
|
Then provide and inject _both the_ **component** _and the service_ in the `TestBed` configuration.
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/welcome/welcome.component.spec.ts"
|
||||||
|
region="class-only-before-each"
|
||||||
|
header="app/welcome/welcome.component.spec.ts (class-only setup)"></code-example>
|
||||||
|
|
||||||
|
Then exercise the component class, remembering to call the [lifecycle hook methods](guide/lifecycle-hooks) as Angular does when running the app.
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/welcome/welcome.component.spec.ts"
|
||||||
|
region="class-only-tests"
|
||||||
|
header="app/welcome/welcome.component.spec.ts (class-only tests)"></code-example>
|
||||||
|
|
||||||
|
## Component DOM testing
|
||||||
|
|
||||||
|
Testing the component _class_ is as easy as [testing a service](guide/testing-services).
|
||||||
|
|
||||||
|
But a component is more than just its class.
|
||||||
|
A component interacts with the DOM and with other components.
|
||||||
|
The _class-only_ tests can tell you about class behavior.
|
||||||
|
They cannot tell you if the component is going to render properly,
|
||||||
|
respond to user input and gestures, or integrate with its parent and child components.
|
||||||
|
|
||||||
|
None of the _class-only_ tests above can answer key questions about how the
|
||||||
|
components actually behave on screen.
|
||||||
|
|
||||||
|
- Is `Lightswitch.clicked()` bound to anything such that the user can invoke it?
|
||||||
|
- Is the `Lightswitch.message` displayed?
|
||||||
|
- Can the user actually select the hero displayed by `DashboardHeroComponent`?
|
||||||
|
- Is the hero name displayed as expected (i.e, in uppercase)?
|
||||||
|
- Is the welcome message displayed by the template of `WelcomeComponent`?
|
||||||
|
|
||||||
|
These may not be troubling questions for the simple components illustrated above.
|
||||||
|
But many components have complex interactions with the DOM elements
|
||||||
|
described in their templates, causing HTML to appear and disappear as
|
||||||
|
the component state changes.
|
||||||
|
|
||||||
|
To answer these kinds of questions, you have to create the DOM elements associated
|
||||||
|
with the components, you must examine the DOM to confirm that component state
|
||||||
|
displays properly at the appropriate times, and you must simulate user interaction
|
||||||
|
with the screen to determine whether those interactions cause the component to
|
||||||
|
behave as expected.
|
||||||
|
|
||||||
|
To write these kinds of test, you'll use additional features of the `TestBed`
|
||||||
|
as well as other testing helpers.
|
||||||
|
|
||||||
|
### CLI-generated tests
|
||||||
|
|
||||||
|
The CLI creates an initial test file for you by default when you ask it to
|
||||||
|
generate a new component.
|
||||||
|
|
||||||
|
For example, the following CLI command generates a `BannerComponent` in the `app/banner` folder (with inline template and styles):
|
||||||
|
|
||||||
|
<code-example language="sh" class="code-shell">
|
||||||
|
ng generate component banner --inline-template --inline-style --module app
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
It also generates an initial test file for the component, `banner-external.component.spec.ts`, that looks like this:
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/banner/banner-initial.component.spec.ts"
|
||||||
|
region="v1"
|
||||||
|
header="app/banner/banner-external.component.spec.ts (initial)"></code-example>
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
Because `compileComponents` is asynchronous, it uses
|
||||||
|
the [`async`](api/core/testing/async) utility
|
||||||
|
function imported from `@angular/core/testing`.
|
||||||
|
|
||||||
|
Please refer to the [async](guide/testing-components-scenarios#async) section for more details.
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
### Reduce the setup
|
||||||
|
|
||||||
|
Only the last three lines of this file actually test the component
|
||||||
|
and all they do is assert that Angular can create the component.
|
||||||
|
|
||||||
|
The rest of the file is boilerplate setup code anticipating more advanced tests that _might_ become necessary if the component evolves into something substantial.
|
||||||
|
|
||||||
|
You'll learn about these advanced test features below.
|
||||||
|
For now, you can radically reduce this test file to a more manageable size:
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/banner/banner-initial.component.spec.ts"
|
||||||
|
region="v2"
|
||||||
|
header="app/banner/banner-initial.component.spec.ts (minimal)"></code-example>
|
||||||
|
|
||||||
|
In this example, the metadata object passed to `TestBed.configureTestingModule`
|
||||||
|
simply declares `BannerComponent`, the component to test.
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/banner/banner-initial.component.spec.ts"
|
||||||
|
region="configureTestingModule">
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
There's no need to declare or import anything else.
|
||||||
|
The default test module is pre-configured with
|
||||||
|
something like the `BrowserModule` from `@angular/platform-browser`.
|
||||||
|
|
||||||
|
Later you'll call `TestBed.configureTestingModule()` with
|
||||||
|
imports, providers, and more declarations to suit your testing needs.
|
||||||
|
Optional `override` methods can further fine-tune aspects of the configuration.
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{@a create-component}
|
||||||
|
|
||||||
|
### _createComponent()_
|
||||||
|
|
||||||
|
After configuring `TestBed`, you call its `createComponent()` method.
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/banner/banner-initial.component.spec.ts"
|
||||||
|
region="createComponent">
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
`TestBed.createComponent()` creates an instance of the `BannerComponent`,
|
||||||
|
adds a corresponding element to the test-runner DOM,
|
||||||
|
and returns a [`ComponentFixture`](#component-fixture).
|
||||||
|
|
||||||
|
<div class="alert is-important">
|
||||||
|
|
||||||
|
Do not re-configure `TestBed` after calling `createComponent`.
|
||||||
|
|
||||||
|
The `createComponent` method freezes the current `TestBed` definition,
|
||||||
|
closing it to further configuration.
|
||||||
|
|
||||||
|
You cannot call any more `TestBed` configuration methods, not `configureTestingModule()`,
|
||||||
|
nor `get()`, nor any of the `override...` methods.
|
||||||
|
If you try, `TestBed` throws an error.
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{@a component-fixture}
|
||||||
|
|
||||||
|
### _ComponentFixture_
|
||||||
|
|
||||||
|
The [ComponentFixture](api/core/testing/ComponentFixture) is a test harness for interacting with the created component and its corresponding element.
|
||||||
|
|
||||||
|
Access the component instance through the fixture and confirm it exists with a Jasmine expectation:
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/banner/banner-initial.component.spec.ts"
|
||||||
|
region="componentInstance">
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
### _beforeEach()_
|
||||||
|
|
||||||
|
You will add more tests as this component evolves.
|
||||||
|
Rather than duplicate the `TestBed` configuration for each test,
|
||||||
|
you refactor to pull the setup into a Jasmine `beforeEach()` and some supporting variables:
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/banner/banner-initial.component.spec.ts"
|
||||||
|
region="v3"
|
||||||
|
></code-example>
|
||||||
|
|
||||||
|
Now add a test that gets the component's element from `fixture.nativeElement` and
|
||||||
|
looks for the expected text.
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/banner/banner-initial.component.spec.ts"
|
||||||
|
region="v4-test-2">
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
{@a native-element}
|
||||||
|
|
||||||
|
### _nativeElement_
|
||||||
|
|
||||||
|
The value of `ComponentFixture.nativeElement` has the `any` type.
|
||||||
|
Later you'll encounter the `DebugElement.nativeElement` and it too has the `any` type.
|
||||||
|
|
||||||
|
Angular can't know at compile time what kind of HTML element the `nativeElement` is or
|
||||||
|
if it even is an HTML element.
|
||||||
|
The app might be running on a _non-browser platform_, such as the server or a
|
||||||
|
[Web Worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API),
|
||||||
|
where the element may have a diminished API or not exist at all.
|
||||||
|
|
||||||
|
The tests in this guide are designed to run in a browser so a
|
||||||
|
`nativeElement` value will always be an `HTMLElement` or
|
||||||
|
one of its derived classes.
|
||||||
|
|
||||||
|
Knowing that it is an `HTMLElement` of some sort, you can use
|
||||||
|
the standard HTML `querySelector` to dive deeper into the element tree.
|
||||||
|
|
||||||
|
Here's another test that calls `HTMLElement.querySelector` to get the paragraph element and look for the banner text:
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/banner/banner-initial.component.spec.ts"
|
||||||
|
region="v4-test-3">
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
{@a debug-element}
|
||||||
|
|
||||||
|
### _DebugElement_
|
||||||
|
|
||||||
|
The Angular _fixture_ provides the component's element directly through the `fixture.nativeElement`.
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/banner/banner-initial.component.spec.ts"
|
||||||
|
region="nativeElement">
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
This is actually a convenience method, implemented as `fixture.debugElement.nativeElement`.
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/banner/banner-initial.component.spec.ts"
|
||||||
|
region="debugElement-nativeElement">
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
There's a good reason for this circuitous path to the element.
|
||||||
|
|
||||||
|
The properties of the `nativeElement` depend upon the runtime environment.
|
||||||
|
You could be running these tests on a _non-browser_ platform that doesn't have a DOM or
|
||||||
|
whose DOM-emulation doesn't support the full `HTMLElement` API.
|
||||||
|
|
||||||
|
Angular relies on the `DebugElement` abstraction to work safely across _all supported platforms_.
|
||||||
|
Instead of creating an HTML element tree, Angular creates a `DebugElement` tree that wraps the _native elements_ for the runtime platform.
|
||||||
|
The `nativeElement` property unwraps the `DebugElement` and returns the platform-specific element object.
|
||||||
|
|
||||||
|
Because the sample tests for this guide are designed to run only in a browser,
|
||||||
|
a `nativeElement` in these tests is always an `HTMLElement`
|
||||||
|
whose familiar methods and properties you can explore within a test.
|
||||||
|
|
||||||
|
Here's the previous test, re-implemented with `fixture.debugElement.nativeElement`:
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/banner/banner-initial.component.spec.ts"
|
||||||
|
region="v4-test-4">
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
The `DebugElement` has other methods and properties that
|
||||||
|
are useful in tests, as you'll see elsewhere in this guide.
|
||||||
|
|
||||||
|
You import the `DebugElement` symbol from the Angular core library.
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/banner/banner-initial.component.spec.ts"
|
||||||
|
region="import-debug-element">
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
{@a by-css}
|
||||||
|
### _By.css()_
|
||||||
|
|
||||||
|
Although the tests in this guide all run in the browser,
|
||||||
|
some apps might run on a different platform at least some of the time.
|
||||||
|
|
||||||
|
For example, the component might render first on the server as part of a strategy to make the application launch faster on poorly connected devices. The server-side renderer might not support the full HTML element API.
|
||||||
|
If it doesn't support `querySelector`, the previous test could fail.
|
||||||
|
|
||||||
|
The `DebugElement` offers query methods that work for all supported platforms.
|
||||||
|
These query methods take a _predicate_ function that returns `true` when a node in the `DebugElement` tree matches the selection criteria.
|
||||||
|
|
||||||
|
You create a _predicate_ with the help of a `By` class imported from a
|
||||||
|
library for the runtime platform. Here's the `By` import for the browser platform:
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/banner/banner-initial.component.spec.ts"
|
||||||
|
region="import-by">
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
The following example re-implements the previous test with
|
||||||
|
`DebugElement.query()` and the browser's `By.css` method.
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/banner/banner-initial.component.spec.ts"
|
||||||
|
region="v4-test-5">
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
Some noteworthy observations:
|
||||||
|
|
||||||
|
- The `By.css()` static method selects `DebugElement` nodes
|
||||||
|
with a [standard CSS selector](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started/Selectors 'CSS selectors').
|
||||||
|
- The query returns a `DebugElement` for the paragraph.
|
||||||
|
- You must unwrap that result to get the paragraph element.
|
||||||
|
|
||||||
|
When you're filtering by CSS selector and only testing properties of a browser's _native element_, the `By.css` approach may be overkill.
|
||||||
|
|
||||||
|
It's often easier and more clear to filter with a standard `HTMLElement` method
|
||||||
|
such as `querySelector()` or `querySelectorAll()`,
|
||||||
|
as you'll see in the next set of tests.
|
||||||
|
|
1826
aio/content/guide/testing-components-scenarios.md
Normal file
1826
aio/content/guide/testing-components-scenarios.md
Normal file
File diff suppressed because it is too large
Load Diff
41
aio/content/guide/testing-pipes.md
Normal file
41
aio/content/guide/testing-pipes.md
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
# Testing Pipes
|
||||||
|
|
||||||
|
You can test [pipes](guide/pipes) without the Angular testing utilities.
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
For the sample app that the testing guides describe, see the <live-example name="testing" embedded-style noDownload>sample app</live-example>.
|
||||||
|
|
||||||
|
For the tests features in the testing guides, see <live-example name="testing" stackblitz="specs" noDownload>tests</live-example>.
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
## Testing the `TitleCasePipe`
|
||||||
|
|
||||||
|
A pipe class has one method, `transform`, that manipulates the input
|
||||||
|
value into a transformed output value.
|
||||||
|
The `transform` implementation rarely interacts with the DOM.
|
||||||
|
Most pipes have no dependence on Angular other than the `@Pipe`
|
||||||
|
metadata and an interface.
|
||||||
|
|
||||||
|
Consider a `TitleCasePipe` that capitalizes the first letter of each word.
|
||||||
|
Here's an implementation with a regular expression.
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/shared/title-case.pipe.ts" header="app/shared/title-case.pipe.ts"></code-example>
|
||||||
|
|
||||||
|
Anything that uses a regular expression is worth testing thoroughly.
|
||||||
|
Use simple Jasmine to explore the expected cases and the edge cases.
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/shared/title-case.pipe.spec.ts" region="excerpt" header="app/shared/title-case.pipe.spec.ts"></code-example>
|
||||||
|
|
||||||
|
{@a write-tests}
|
||||||
|
|
||||||
|
## Writing DOM tests to support a pipe test
|
||||||
|
|
||||||
|
These are tests of the pipe _in isolation_.
|
||||||
|
They can't tell if the `TitleCasePipe` is working properly as applied in the application components.
|
||||||
|
|
||||||
|
Consider adding component tests such as this one:
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/hero/hero-detail.component.spec.ts" region="title-case-pipe" header="app/hero/hero-detail.component.spec.ts (pipe test)"></code-example>
|
||||||
|
|
199
aio/content/guide/testing-services.md
Normal file
199
aio/content/guide/testing-services.md
Normal file
@ -0,0 +1,199 @@
|
|||||||
|
# Testing services
|
||||||
|
|
||||||
|
|
||||||
|
To check that your services are working as you intend, you can write tests specifically for them.
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
For the sample app that the testing guides describe, see the <live-example name="testing" embedded-style noDownload>sample app</live-example>.
|
||||||
|
|
||||||
|
For the tests features in the testing guides, see <live-example name="testing" stackblitz="specs" noDownload>tests</live-example>.
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
Services are often the easiest files to unit test.
|
||||||
|
Here are some synchronous and asynchronous unit tests of the `ValueService`
|
||||||
|
written without assistance from Angular testing utilities.
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/demo/demo.spec.ts" region="ValueService" header="app/demo/demo.spec.ts"></code-example>
|
||||||
|
|
||||||
|
{@a services-with-dependencies}
|
||||||
|
|
||||||
|
## Services with dependencies
|
||||||
|
|
||||||
|
Services often depend on other services that Angular injects into the constructor.
|
||||||
|
In many cases, it's easy to create and _inject_ these dependencies by hand while
|
||||||
|
calling the service's constructor.
|
||||||
|
|
||||||
|
The `MasterService` is a simple example:
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/demo/demo.ts" region="MasterService" header="app/demo/demo.ts"></code-example>
|
||||||
|
|
||||||
|
`MasterService` delegates its only method, `getValue`, to the injected `ValueService`.
|
||||||
|
|
||||||
|
Here are several ways to test it.
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/demo/demo.spec.ts" region="MasterService" header="app/demo/demo.spec.ts"></code-example>
|
||||||
|
|
||||||
|
The first test creates a `ValueService` with `new` and passes it to the `MasterService` constructor.
|
||||||
|
|
||||||
|
However, injecting the real service rarely works well as most dependent services are difficult to create and control.
|
||||||
|
|
||||||
|
Instead you can mock the dependency, use a dummy value, or create a
|
||||||
|
[spy](https://jasmine.github.io/2.0/introduction.html#section-Spies)
|
||||||
|
on the pertinent service method.
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
Prefer spies as they are usually the easiest way to mock services.
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
These standard testing techniques are great for unit testing services in isolation.
|
||||||
|
|
||||||
|
However, you almost always inject services into application classes using Angular
|
||||||
|
dependency injection and you should have tests that reflect that usage pattern.
|
||||||
|
Angular testing utilities make it easy to investigate how injected services behave.
|
||||||
|
|
||||||
|
## Testing services with the _TestBed_
|
||||||
|
|
||||||
|
Your app relies on Angular [dependency injection (DI)](guide/dependency-injection)
|
||||||
|
to create services.
|
||||||
|
When a service has a dependent service, DI finds or creates that dependent service.
|
||||||
|
And if that dependent service has its own dependencies, DI finds-or-creates them as well.
|
||||||
|
|
||||||
|
As service _consumer_, you don't worry about any of this.
|
||||||
|
You don't worry about the order of constructor arguments or how they're created.
|
||||||
|
|
||||||
|
As a service _tester_, you must at least think about the first level of service dependencies
|
||||||
|
but you _can_ let Angular DI do the service creation and deal with constructor argument order
|
||||||
|
when you use the `TestBed` testing utility to provide and create services.
|
||||||
|
|
||||||
|
{@a testbed}
|
||||||
|
|
||||||
|
## Angular _TestBed_
|
||||||
|
|
||||||
|
The `TestBed` is the most important of the Angular testing utilities.
|
||||||
|
The `TestBed` creates a dynamically-constructed Angular _test_ module that emulates
|
||||||
|
an Angular [@NgModule](guide/ngmodules).
|
||||||
|
|
||||||
|
The `TestBed.configureTestingModule()` method takes a metadata object that can have most of the properties of an [@NgModule](guide/ngmodules).
|
||||||
|
|
||||||
|
To test a service, you set the `providers` metadata property with an
|
||||||
|
array of the services that you'll test or mock.
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/demo/demo.testbed.spec.ts" region="value-service-before-each" header="app/demo/demo.testbed.spec.ts (provide ValueService in beforeEach)"></code-example>
|
||||||
|
|
||||||
|
Then inject it inside a test by calling `TestBed.inject()` with the service class as the argument.
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
**Note:** `TestBed.get()` was deprecated as of Angular version 9.
|
||||||
|
To help minimize breaking changes, Angular introduces a new function called `TestBed.inject()`, which you should use instead.
|
||||||
|
For information on the removal of `TestBed.get()`,
|
||||||
|
see its entry in the [Deprecations index](guide/deprecations#index).
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/demo/demo.testbed.spec.ts" region="value-service-inject-it"></code-example>
|
||||||
|
|
||||||
|
Or inside the `beforeEach()` if you prefer to inject the service as part of your setup.
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/demo/demo.testbed.spec.ts" region="value-service-inject-before-each"> </code-example>
|
||||||
|
|
||||||
|
When testing a service with a dependency, provide the mock in the `providers` array.
|
||||||
|
|
||||||
|
In the following example, the mock is a spy object.
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/demo/demo.testbed.spec.ts" region="master-service-before-each"></code-example>
|
||||||
|
|
||||||
|
The test consumes that spy in the same way it did earlier.
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/demo/demo.testbed.spec.ts" region="master-service-it">
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
{@a no-before-each}
|
||||||
|
|
||||||
|
## Testing without _beforeEach()_
|
||||||
|
|
||||||
|
Most test suites in this guide call `beforeEach()` to set the preconditions for each `it()` test
|
||||||
|
and rely on the `TestBed` to create classes and inject services.
|
||||||
|
|
||||||
|
There's another school of testing that never calls `beforeEach()` and prefers to create classes explicitly rather than use the `TestBed`.
|
||||||
|
|
||||||
|
Here's how you might rewrite one of the `MasterService` tests in that style.
|
||||||
|
|
||||||
|
Begin by putting re-usable, preparatory code in a _setup_ function instead of `beforeEach()`.
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/demo/demo.spec.ts"
|
||||||
|
region="no-before-each-setup"
|
||||||
|
header="app/demo/demo.spec.ts (setup)"></code-example>
|
||||||
|
|
||||||
|
The `setup()` function returns an object literal
|
||||||
|
with the variables, such as `masterService`, that a test might reference.
|
||||||
|
You don't define _semi-global_ variables (e.g., `let masterService: MasterService`)
|
||||||
|
in the body of the `describe()`.
|
||||||
|
|
||||||
|
Then each test invokes `setup()` in its first line, before continuing
|
||||||
|
with steps that manipulate the test subject and assert expectations.
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/demo/demo.spec.ts"
|
||||||
|
region="no-before-each-test"></code-example>
|
||||||
|
|
||||||
|
Notice how the test uses
|
||||||
|
[_destructuring assignment_](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment)
|
||||||
|
to extract the setup variables that it needs.
|
||||||
|
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/demo/demo.spec.ts"
|
||||||
|
region="no-before-each-setup-call">
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
Many developers feel this approach is cleaner and more explicit than the
|
||||||
|
traditional `beforeEach()` style.
|
||||||
|
|
||||||
|
Although this testing guide follows the traditional style and
|
||||||
|
the default [CLI schematics](https://github.com/angular/angular-cli)
|
||||||
|
generate test files with `beforeEach()` and `TestBed`,
|
||||||
|
feel free to adopt _this alternative approach_ in your own projects.
|
||||||
|
|
||||||
|
## Testing HTTP services
|
||||||
|
|
||||||
|
Data services that make HTTP calls to remote servers typically inject and delegate
|
||||||
|
to the Angular [`HttpClient`](guide/http) service for XHR calls.
|
||||||
|
|
||||||
|
You can test a data service with an injected `HttpClient` spy as you would
|
||||||
|
test any service with a dependency.
|
||||||
|
<code-example
|
||||||
|
path="testing/src/app/model/hero.service.spec.ts"
|
||||||
|
region="test-with-spies"
|
||||||
|
header="app/model/hero.service.spec.ts (tests with spies)">
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
<div class="alert is-important">
|
||||||
|
|
||||||
|
The `HeroService` methods return `Observables`. You must
|
||||||
|
_subscribe_ to an observable to (a) cause it to execute and (b)
|
||||||
|
assert that the method succeeds or fails.
|
||||||
|
|
||||||
|
The `subscribe()` method takes a success (`next`) and fail (`error`) callback.
|
||||||
|
Make sure you provide _both_ callbacks so that you capture errors.
|
||||||
|
Neglecting to do so produces an asynchronous uncaught observable error that
|
||||||
|
the test runner will likely attribute to a completely different test.
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
## _HttpClientTestingModule_
|
||||||
|
|
||||||
|
Extended interactions between a data service and the `HttpClient` can be complex
|
||||||
|
and difficult to mock with spies.
|
||||||
|
|
||||||
|
The `HttpClientTestingModule` can make these testing scenarios more manageable.
|
||||||
|
|
||||||
|
While the _code sample_ accompanying this guide demonstrates `HttpClientTestingModule`,
|
||||||
|
this page defers to the [Http guide](guide/http#testing-http-requests),
|
||||||
|
which covers testing with the `HttpClientTestingModule` in detail.
|
||||||
|
|
794
aio/content/guide/testing-utility-apis.md
Normal file
794
aio/content/guide/testing-utility-apis.md
Normal file
@ -0,0 +1,794 @@
|
|||||||
|
# Testing Utility APIs
|
||||||
|
|
||||||
|
This page describes the most useful Angular testing features.
|
||||||
|
|
||||||
|
The Angular testing utilities include the `TestBed`, the `ComponentFixture`, and a handful of functions that control the test environment.
|
||||||
|
The [_TestBed_](#testbed-api-summary) and [_ComponentFixture_](#component-fixture-api-summary) classes are covered separately.
|
||||||
|
|
||||||
|
Here's a summary of the stand-alone functions, in order of likely utility:
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Function
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Description
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>async</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Runs the body of a test (`it`) or setup (`beforeEach`) function within a special _async test zone_.
|
||||||
|
See [discussion above](guide/testing-components-scenarios#async).
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>fakeAsync</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Runs the body of a test (`it`) within a special _fakeAsync test zone_, enabling
|
||||||
|
a linear control flow coding style. See [discussion above](guide/testing-components-scenarios#fake-async).
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>tick</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Simulates the passage of time and the completion of pending asynchronous activities
|
||||||
|
by flushing both _timer_ and _micro-task_ queues within the _fakeAsync test zone_.
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
The curious, dedicated reader might enjoy this lengthy blog post,
|
||||||
|
["_Tasks, microtasks, queues and schedules_"](https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/).
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
Accepts an optional argument that moves the virtual clock forward
|
||||||
|
by the specified number of milliseconds,
|
||||||
|
clearing asynchronous activities scheduled within that timeframe.
|
||||||
|
See [discussion above](guide/testing-components-scenarios#tick).
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>inject</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Injects one or more services from the current `TestBed` injector into a test function.
|
||||||
|
It cannot inject a service provided by the component itself.
|
||||||
|
See discussion of the [debugElement.injector](guide/testing-components-scenarios#get-injected-services).
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>discardPeriodicTasks</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
When a `fakeAsync()` test ends with pending timer event _tasks_ (queued `setTimeOut` and `setInterval` callbacks),
|
||||||
|
the test fails with a clear error message.
|
||||||
|
|
||||||
|
In general, a test should end with no queued tasks.
|
||||||
|
When pending timer tasks are expected, call `discardPeriodicTasks` to flush the _task_ queue
|
||||||
|
and avoid the error.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>flushMicrotasks</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
When a `fakeAsync()` test ends with pending _micro-tasks_ such as unresolved promises,
|
||||||
|
the test fails with a clear error message.
|
||||||
|
|
||||||
|
In general, a test should wait for micro-tasks to finish.
|
||||||
|
When pending microtasks are expected, call `flushMicrotasks` to flush the _micro-task_ queue
|
||||||
|
and avoid the error.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>ComponentFixtureAutoDetect</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
A provider token for a service that turns on [automatic change detection](guide/testing-components-scenarios#automatic-change-detection).
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>getTestBed</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Gets the current instance of the `TestBed`.
|
||||||
|
Usually unnecessary because the static class methods of the `TestBed` class are typically sufficient.
|
||||||
|
The `TestBed` instance exposes a few rarely used members that are not available as
|
||||||
|
static methods.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
{@a testbed-class-summary}
|
||||||
|
|
||||||
|
## _TestBed_ class summary
|
||||||
|
|
||||||
|
The `TestBed` class is one of the principal Angular testing utilities.
|
||||||
|
Its API is quite large and can be overwhelming until you've explored it,
|
||||||
|
a little at a time. Read the early part of this guide first
|
||||||
|
to get the basics before trying to absorb the full API.
|
||||||
|
|
||||||
|
The module definition passed to `configureTestingModule`
|
||||||
|
is a subset of the `@NgModule` metadata properties.
|
||||||
|
|
||||||
|
<code-example language="javascript">
|
||||||
|
type TestModuleMetadata = {
|
||||||
|
providers?: any[];
|
||||||
|
declarations?: any[];
|
||||||
|
imports?: any[];
|
||||||
|
schemas?: Array<SchemaMetadata | any[]>;
|
||||||
|
};
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
{@a metadata-override-object}
|
||||||
|
|
||||||
|
Each override method takes a `MetadataOverride<T>` where `T` is the kind of metadata
|
||||||
|
appropriate to the method, that is, the parameter of an `@NgModule`,
|
||||||
|
`@Component`, `@Directive`, or `@Pipe`.
|
||||||
|
|
||||||
|
<code-example language="javascript">
|
||||||
|
type MetadataOverride<T> = {
|
||||||
|
add?: Partial<T>;
|
||||||
|
remove?: Partial<T>;
|
||||||
|
set?: Partial<T>;
|
||||||
|
};
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
{@a testbed-methods}
|
||||||
|
{@a testbed-api-summary}
|
||||||
|
|
||||||
|
The `TestBed` API consists of static class methods that either update or reference a _global_ instance of the `TestBed`.
|
||||||
|
|
||||||
|
Internally, all static methods cover methods of the current runtime `TestBed` instance,
|
||||||
|
which is also returned by the `getTestBed()` function.
|
||||||
|
|
||||||
|
Call `TestBed` methods _within_ a `beforeEach()` to ensure a fresh start before each individual test.
|
||||||
|
|
||||||
|
Here are the most important static methods, in order of likely utility.
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Methods
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Description
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>configureTestingModule</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
The testing shims (`karma-test-shim`, `browser-test-shim`)
|
||||||
|
establish the [initial test environment](guide/testing) and a default testing module.
|
||||||
|
The default testing module is configured with basic declaratives and some Angular service substitutes that every tester needs.
|
||||||
|
|
||||||
|
Call `configureTestingModule` to refine the testing module configuration for a particular set of tests
|
||||||
|
by adding and removing imports, declarations (of components, directives, and pipes), and providers.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>compileComponents</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Compile the testing module asynchronously after you've finished configuring it.
|
||||||
|
You **must** call this method if _any_ of the testing module components have a `templateUrl`
|
||||||
|
or `styleUrls` because fetching component template and style files is necessarily asynchronous.
|
||||||
|
See [above](guide/testing-components-scenarios#compile-components).
|
||||||
|
|
||||||
|
After calling `compileComponents`, the `TestBed` configuration is frozen for the duration of the current spec.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>createComponent<T></code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Create an instance of a component of type `T` based on the current `TestBed` configuration.
|
||||||
|
After calling `compileComponent`, the `TestBed` configuration is frozen for the duration of the current spec.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>overrideModule</code>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Replace metadata for the given `NgModule`. Recall that modules can import other modules.
|
||||||
|
The `overrideModule` method can reach deeply into the current testing module to
|
||||||
|
modify one of these inner modules.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>overrideComponent</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Replace metadata for the given component class, which could be nested deeply
|
||||||
|
within an inner module.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>overrideDirective</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Replace metadata for the given directive class, which could be nested deeply
|
||||||
|
within an inner module.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>overridePipe</code>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Replace metadata for the given pipe class, which could be nested deeply
|
||||||
|
within an inner module.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
{@a testbed-inject}
|
||||||
|
<code>inject</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Retrieve a service from the current `TestBed` injector.
|
||||||
|
|
||||||
|
The `inject` function is often adequate for this purpose.
|
||||||
|
But `inject` throws an error if it can't provide the service.
|
||||||
|
|
||||||
|
What if the service is optional?
|
||||||
|
|
||||||
|
The `TestBed.inject()` method takes an optional second parameter,
|
||||||
|
the object to return if Angular can't find the provider
|
||||||
|
(`null` in this example):
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/demo/demo.testbed.spec.ts" region="testbed-get-w-null" header="app/demo/demo.testbed.spec.ts"></code-example>
|
||||||
|
|
||||||
|
After calling `TestBed.inject`, the `TestBed` configuration is frozen for the duration of the current spec.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
{@a testbed-initTestEnvironment}
|
||||||
|
<code>initTestEnvironment</code>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Initialize the testing environment for the entire test run.
|
||||||
|
|
||||||
|
The testing shims (`karma-test-shim`, `browser-test-shim`) call it for you
|
||||||
|
so there is rarely a reason for you to call it yourself.
|
||||||
|
|
||||||
|
You may call this method _exactly once_. If you must change
|
||||||
|
this default in the middle of your test run, call `resetTestEnvironment` first.
|
||||||
|
|
||||||
|
Specify the Angular compiler factory, a `PlatformRef`, and a default Angular testing module.
|
||||||
|
Alternatives for non-browser platforms are available in the general form
|
||||||
|
`@angular/platform-<platform_name>/testing/<platform_name>`.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>resetTestEnvironment</code>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Reset the initial test environment, including the default testing module.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
A few of the `TestBed` instance methods are not covered by static `TestBed` _class_ methods.
|
||||||
|
These are rarely needed.
|
||||||
|
|
||||||
|
{@a component-fixture-api-summary}
|
||||||
|
|
||||||
|
## The _ComponentFixture_
|
||||||
|
|
||||||
|
The `TestBed.createComponent<T>`
|
||||||
|
creates an instance of the component `T`
|
||||||
|
and returns a strongly typed `ComponentFixture` for that component.
|
||||||
|
|
||||||
|
The `ComponentFixture` properties and methods provide access to the component,
|
||||||
|
its DOM representation, and aspects of its Angular environment.
|
||||||
|
|
||||||
|
{@a component-fixture-properties}
|
||||||
|
|
||||||
|
### _ComponentFixture_ properties
|
||||||
|
|
||||||
|
Here are the most important properties for testers, in order of likely utility.
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Properties
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Description
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>componentInstance</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
The instance of the component class created by `TestBed.createComponent`.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>debugElement</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
The `DebugElement` associated with the root element of the component.
|
||||||
|
|
||||||
|
The `debugElement` provides insight into the component and its DOM element during test and debugging.
|
||||||
|
It's a critical property for testers. The most interesting members are covered [below](#debug-element-details).
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>nativeElement</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
The native DOM element at the root of the component.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>changeDetectorRef</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
The `ChangeDetectorRef` for the component.
|
||||||
|
|
||||||
|
The `ChangeDetectorRef` is most valuable when testing a
|
||||||
|
component that has the `ChangeDetectionStrategy.OnPush` method
|
||||||
|
or the component's change detection is under your programmatic control.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{@a component-fixture-methods}
|
||||||
|
|
||||||
|
### _ComponentFixture_ methods
|
||||||
|
|
||||||
|
The _fixture_ methods cause Angular to perform certain tasks on the component tree.
|
||||||
|
Call these method to trigger Angular behavior in response to simulated user action.
|
||||||
|
|
||||||
|
Here are the most useful methods for testers.
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Methods
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Description
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>detectChanges</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Trigger a change detection cycle for the component.
|
||||||
|
|
||||||
|
Call it to initialize the component (it calls `ngOnInit`) and after your
|
||||||
|
test code, change the component's data bound property values.
|
||||||
|
Angular can't see that you've changed `personComponent.name` and won't update the `name`
|
||||||
|
binding until you call `detectChanges`.
|
||||||
|
|
||||||
|
Runs `checkNoChanges` afterwards to confirm that there are no circular updates unless
|
||||||
|
called as `detectChanges(false)`;
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>autoDetectChanges</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Set this to `true` when you want the fixture to detect changes automatically.
|
||||||
|
|
||||||
|
When autodetect is `true`, the test fixture calls `detectChanges` immediately
|
||||||
|
after creating the component. Then it listens for pertinent zone events
|
||||||
|
and calls `detectChanges` accordingly.
|
||||||
|
When your test code modifies component property values directly,
|
||||||
|
you probably still have to call `fixture.detectChanges` to trigger data binding updates.
|
||||||
|
|
||||||
|
The default is `false`. Testers who prefer fine control over test behavior
|
||||||
|
tend to keep it `false`.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>checkNoChanges</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Do a change detection run to make sure there are no pending changes.
|
||||||
|
Throws an exceptions if there are.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>isStable</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
If the fixture is currently _stable_, returns `true`.
|
||||||
|
If there are async tasks that have not completed, returns `false`.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>whenStable</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Returns a promise that resolves when the fixture is stable.
|
||||||
|
|
||||||
|
To resume testing after completion of asynchronous activity or
|
||||||
|
asynchronous change detection, hook that promise.
|
||||||
|
See [above](guide/testing-components-scenarios#when-stable).
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>destroy</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Trigger component destruction.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{@a debug-element-details}
|
||||||
|
|
||||||
|
#### _DebugElement_
|
||||||
|
|
||||||
|
The `DebugElement` provides crucial insights into the component's DOM representation.
|
||||||
|
|
||||||
|
From the test root component's `DebugElement` returned by `fixture.debugElement`,
|
||||||
|
you can walk (and query) the fixture's entire element and component subtrees.
|
||||||
|
|
||||||
|
Here are the most useful `DebugElement` members for testers, in approximate order of utility:
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Member
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Description
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>nativeElement</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
The corresponding DOM element in the browser (null for WebWorkers).
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>query</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Calling `query(predicate: Predicate<DebugElement>)` returns the first `DebugElement`
|
||||||
|
that matches the [predicate](#query-predicate) at any depth in the subtree.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>queryAll</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Calling `queryAll(predicate: Predicate<DebugElement>)` returns all `DebugElements`
|
||||||
|
that matches the [predicate](#query-predicate) at any depth in subtree.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>injector</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
The host dependency injector.
|
||||||
|
For example, the root element's component instance injector.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>componentInstance</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
The element's own component instance, if it has one.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>context</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
An object that provides parent context for this element.
|
||||||
|
Often an ancestor component instance that governs this element.
|
||||||
|
|
||||||
|
When an element is repeated within `*ngFor`, the context is an `NgForRow` whose `$implicit`
|
||||||
|
property is the value of the row instance value.
|
||||||
|
For example, the `hero` in `*ngFor="let hero of heroes"`.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>children</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
The immediate `DebugElement` children. Walk the tree by descending through `children`.
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
`DebugElement` also has `childNodes`, a list of `DebugNode` objects.
|
||||||
|
`DebugElement` derives from `DebugNode` objects and there are often
|
||||||
|
more nodes than elements. Testers can usually ignore plain nodes.
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>parent</code>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
The `DebugElement` parent. Null if this is the root element.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>name</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
The element tag name, if it is an element.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>triggerEventHandler</code>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Triggers the event by its name if there is a corresponding listener
|
||||||
|
in the element's `listeners` collection.
|
||||||
|
The second parameter is the _event object_ expected by the handler.
|
||||||
|
See [above](guide/testing-components-scenarios#trigger-event-handler).
|
||||||
|
|
||||||
|
If the event lacks a listener or there's some other problem,
|
||||||
|
consider calling `nativeElement.dispatchEvent(eventObject)`.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>listeners</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
The callbacks attached to the component's `@Output` properties and/or the element's event properties.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>providerTokens</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
This component's injector lookup tokens.
|
||||||
|
Includes the component itself plus the tokens that the component lists in its `providers` metadata.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>source</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Where to find this element in the source component template.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td style="vertical-align: top">
|
||||||
|
<code>references</code>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Dictionary of objects associated with template local variables (e.g. `#foo`),
|
||||||
|
keyed by the local variable name.
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{@a query-predicate}
|
||||||
|
|
||||||
|
The `DebugElement.query(predicate)` and `DebugElement.queryAll(predicate)` methods take a
|
||||||
|
predicate that filters the source element's subtree for matching `DebugElement`.
|
||||||
|
|
||||||
|
The predicate is any method that takes a `DebugElement` and returns a _truthy_ value.
|
||||||
|
The following example finds all `DebugElements` with a reference to a template local variable named "content":
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/demo/demo.testbed.spec.ts" region="custom-predicate" header="app/demo/demo.testbed.spec.ts"></code-example>
|
||||||
|
|
||||||
|
The Angular `By` class has three static methods for common predicates:
|
||||||
|
|
||||||
|
- `By.all` - return all elements.
|
||||||
|
- `By.css(selector)` - return elements with matching CSS selectors.
|
||||||
|
- `By.directive(directive)` - return elements that Angular matched to an instance of the directive class.
|
||||||
|
|
||||||
|
<code-example path="testing/src/app/hero/hero-list.component.spec.ts" region="by" header="app/hero/hero-list.component.spec.ts"></code-example>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
@ -15,22 +15,49 @@ that are important to Angular developers, including details about the following
|
|||||||
|
|
||||||
{@a tsconfig}
|
{@a tsconfig}
|
||||||
|
|
||||||
## TypeScript configuration
|
## Configuration files
|
||||||
|
|
||||||
A TypeScript configuration file called `tsconfig.json` guides the compiler as it generates JavaScript files for a project.
|
A given Angular workspace contains several TypeScript configuration files.
|
||||||
This file contains options and flags that are essential for Angular applications.
|
At the root level, there are two main TypeScript configuration files: a `tsconfig.json` file and a `tsconfig.base.json` file.
|
||||||
Typically, the file is found at the [root level of the workspace](guide/file-structure).
|
|
||||||
|
The `tsconfig.json` file is a ["Solution Style"](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#support-for-solution-style-tsconfigjson-files) TypeScript configuration file.
|
||||||
|
Code editors and TypeScript’s language server use this file to improve development experience.
|
||||||
|
Compilers do not use this file.
|
||||||
|
|
||||||
|
The `tsconfig.json` file contains a list of paths to the other TypeScript configuration files used in the workspace.
|
||||||
|
|
||||||
|
<code-example lang="json" header="tsconfig.json" linenums="false">
|
||||||
|
{
|
||||||
|
"files": [],
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"path": "./tsconfig.app.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./tsconfig.spec.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./projects/my-lib/tsconfig.lib.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
</code-example>
|
||||||
|
|
||||||
|
The `tsconfig.base.json` file specifies the base TypeScript and Angular compiler options that all projects in the workspace inherit.
|
||||||
|
|
||||||
|
The TypeScript and Angular have a wide range of options which can be used to configure type-checking features and generated output.
|
||||||
|
For more information, see the [Configuration inheritance with extends](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#configuration-inheritance-with-extends) section of the TypeScript documentation.
|
||||||
|
|
||||||
<div class="alert is-helpful">
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
For details about `tsconfig.json`, see the official
|
For more information TypeScript configuration files, see the official [TypeScript wiki](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html)
|
||||||
[TypeScript wiki](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html).
|
For details about configuration inheritance, see the [Configuration inheritance with extends](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#configuration-inheritance-with-extends) section.
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
The initial `tsconfig.json` for an Angular app typically looks like the following example.
|
The initial `tsconfig.base.json` for an Angular workspace typically looks like the following example.
|
||||||
|
|
||||||
<code-example lang="json" header="tsconfig.json" linenums="false">
|
<code-example lang="json" header="tsconfig.base.json" linenums="false">
|
||||||
{
|
{
|
||||||
"compileOnSave": false,
|
"compileOnSave": false,
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
@ -40,25 +67,22 @@ The initial `tsconfig.json` for an Angular app typically looks like the followin
|
|||||||
"declaration": false,
|
"declaration": false,
|
||||||
"downlevelIteration": true,
|
"downlevelIteration": true,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"module": "esnext",
|
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"importHelpers": true,
|
"importHelpers": true,
|
||||||
"target": "es2015",
|
"target": "es2015",
|
||||||
"typeRoots": [
|
"module": "es2020",
|
||||||
"node_modules/@types"
|
|
||||||
],
|
|
||||||
"lib": [
|
"lib": [
|
||||||
"es2018",
|
"es2018",
|
||||||
"dom"
|
"dom"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
"angularCompilerOptions": {
|
|
||||||
"strictTemplates": true,
|
|
||||||
"strictInjectionParameters": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</code-example>
|
</code-example>
|
||||||
|
|
||||||
|
### Strict mode
|
||||||
|
|
||||||
|
When you create new workspaces and projects, you have the option to use Angular's strict mode, which can help you write better, more maintainable code.
|
||||||
|
For more information, see [Strict mode](/guide/strict-mode).
|
||||||
|
|
||||||
{@a noImplicitAny}
|
{@a noImplicitAny}
|
||||||
|
|
||||||
|
@ -48,11 +48,11 @@ src/
|
|||||||
app/ ... <i>application code</i>
|
app/ ... <i>application code</i>
|
||||||
app.server.module.ts <i>* server-side application module</i>
|
app.server.module.ts <i>* server-side application module</i>
|
||||||
server.ts <i>* express web server</i>
|
server.ts <i>* express web server</i>
|
||||||
tsconfig.json <i>TypeScript client configuration</i>
|
tsconfig.json <i>TypeScript solution style configuration</i>
|
||||||
tsconfig.app.json <i>TypeScript client configuration</i>
|
tsconfig.base.json <i>TypeScript base configuration</i>
|
||||||
tsconfig.server.json <i>* TypeScript server configuration</i>
|
tsconfig.app.json <i>TypeScript browser application configuration</i>
|
||||||
tsconfig.spec.json <i>TypeScript spec configuration</i>
|
tsconfig.server.json <i>TypeScript server application configuration</i>
|
||||||
package.json <i>npm configuration</i>
|
tsconfig.spec.json <i>TypeScript tests configuration</i>
|
||||||
</code-example>
|
</code-example>
|
||||||
|
|
||||||
The files marked with `*` are new and not in the original tutorial sample.
|
The files marked with `*` are new and not in the original tutorial sample.
|
||||||
|
82
aio/content/guide/updating-to-version-10.md
Normal file
82
aio/content/guide/updating-to-version-10.md
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
# Updating to Angular version 10
|
||||||
|
|
||||||
|
This guide contains information related to updating to version 10 of Angular.
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
For information on upgrading to Angular version 9, see [Updating to Angular version 9](https://v9.angular.io/guide/updating-to-version-9).
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
## Updating CLI Apps
|
||||||
|
|
||||||
|
For step-by-step instructions on how to update to the latest Angular release (and leverage our automated migration tools to do so), use the interactive update guide at [update.angular.io](https://update.angular.io).
|
||||||
|
|
||||||
|
If you're curious about the specific migrations being run by the CLI, see the [automated migrations section](#migrations) for details on what code is changing and why.
|
||||||
|
|
||||||
|
## Changes and Deprecations in Version 10
|
||||||
|
|
||||||
|
<div class="alert is-helpful">
|
||||||
|
|
||||||
|
For information about Angular's deprecation and removal practices, see [Angular Release Practices](guide/releases#deprecation-practices "Angular Release Practices: Deprecation practices").
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{@a breaking-changes}
|
||||||
|
### New Breaking Changes
|
||||||
|
|
||||||
|
* Typescript 3.6, 3.7, and 3.8 are no longer supported. Please update to Typescript 3.9.
|
||||||
|
* Input fields of type `number` fire the `valueChanges` event only once per value change (as opposed to twice in some cases). See [PR 36087](https://github.com/angular/angular/pull/36087).
|
||||||
|
* The `minLength` and `maxLength` validators only validate values that have a numeric `length` property. See [PR 36157](https://github.com/angular/angular/pull/36157).
|
||||||
|
* Templates with unknown property bindings or unknown element names now log errors instead of warnings. See [PR 36399](https://github.com/angular/angular/pull/36399).
|
||||||
|
* `UrlMatcher` can now return `null` values. See [PR 36402](https://github.com/angular/angular/pull/36402).
|
||||||
|
* Transplanted views now refresh at insertion point only. See [PR 35968](https://github.com/angular/angular/pull/35968).
|
||||||
|
* Formatting times with the `b` or `B` format codes now supports time periods that cross midnight. See [PR 36611](https://github.com/angular/angular/pull/36611).
|
||||||
|
* Navigation is canceled for routes with at least one empty resolver. See [PR 24621](https://github.com/angular/angular/pull/24621).
|
||||||
|
|
||||||
|
{@a deprecations}
|
||||||
|
### New Deprecations
|
||||||
|
|
||||||
|
| Area | API or Feature | May be removed in |
|
||||||
|
| ----------------------------- | --------------------------------------------------------------------------- | ----------------- |
|
||||||
|
| `@angular/core` | [`WrappedValue`](guide/deprecations#wrapped-value) | <!--v10--> v12 |
|
||||||
|
| browser support | [`IE 9, 10, and IE Mobile`](guide/deprecations#ie-9-10-and-ie-mobile-support) | <!--v10--> v11 |
|
||||||
|
|
||||||
|
|
||||||
|
{@a removals}
|
||||||
|
### New Removals of Deprecated APIs
|
||||||
|
|
||||||
|
The following APIs have been removed starting with version 10.0.0*:
|
||||||
|
|
||||||
|
| Package | API | Replacement | Notes |
|
||||||
|
| ---------------- | -------------- | ----------- | ----- |
|
||||||
|
| `@angular/core` | Undecorated base classes that use Angular features | Add Angular decorator | See [migration guide](guide/migration-undecorated-classes) for more info |
|
||||||
|
| `@angular/core` | `ModuleWithProviders` without a generic | `ModuleWithProviders` with a generic | See [migration guide](guide/migration-module-with-providers) for more info |
|
||||||
|
| `@angular/core` | Style Sanitization | no action needed | See [style sanitization API removal](/guide/deprecations#style-sanitization) for more info
|
||||||
|
| `@angular/bazel` | [`Bazel builder and schematics`](guide/deprecations#bazelbuilder) | `bazelbuild/rules_nodejs` | [More info](https://github.com/angular/angular/tree/10.0.x/packages/bazel/src/schematics) |
|
||||||
|
|
||||||
|
|
||||||
|
*To see APIs removed in version 9, check out this guide on the [version 9 docs site](https://v9.angular.io/guide/deprecations#removed).
|
||||||
|
|
||||||
|
{@a ivy}
|
||||||
|
|
||||||
|
## Ivy features and compatibility
|
||||||
|
|
||||||
|
Since version 9, Angular Ivy is the default rendering engine. If you haven't heard of Ivy, you can read more about it in the [Angular Ivy guide](guide/ivy).
|
||||||
|
|
||||||
|
* Among other features, Ivy introduces more comprehensive type-checking within templates. For details, see [Template Type-checking](guide/template-typecheck).
|
||||||
|
|
||||||
|
* For general guidance on debugging and a list of minor changes associated with Ivy, see the [Ivy compatibility guide](guide/ivy-compatibility).
|
||||||
|
|
||||||
|
* For help with opting out of Ivy, see the instructions [here](guide/ivy#opting-out-of-angular-ivy).
|
||||||
|
|
||||||
|
{@a migrations}
|
||||||
|
## Automated Migrations for Version 10
|
||||||
|
|
||||||
|
Read about the migrations the CLI handles for you automatically:
|
||||||
|
|
||||||
|
* [Migrating missing `@Directive()`/`@Component()` decorators](guide/migration-undecorated-classes)
|
||||||
|
* [Migrating `ModuleWithProviders`](guide/migration-module-with-providers)
|
||||||
|
* [Solution-style `tsconfig.json` migration](guide/migration-solution-style-tsconfig)
|
||||||
|
* [`tslib` direct dependency migration](guide/migration-update-libraries-tslib)
|
||||||
|
* [Update `module` and `target` compiler options migration](guide/migration-update-module-and-target-compiler-options)
|
@ -1,90 +0,0 @@
|
|||||||
# Updating to Angular version 9
|
|
||||||
|
|
||||||
This guide contains information related to updating to version 9 of Angular.
|
|
||||||
|
|
||||||
## Updating CLI Apps
|
|
||||||
|
|
||||||
For step-by-step instructions on how to update to the latest Angular release (and leverage our automated migration tools to do so), use the interactive update guide at [update.angular.io](https://update.angular.io).
|
|
||||||
|
|
||||||
If you're curious about the specific migrations being run by the CLI, see the [automated migrations section](#migrations) for details on what code is changing and why.
|
|
||||||
|
|
||||||
## Changes and Deprecations in Version 9
|
|
||||||
|
|
||||||
<div class="alert is-helpful">
|
|
||||||
|
|
||||||
For information about Angular's deprecation and removal practices, see [Angular Release Practices](guide/releases#deprecation-practices "Angular Release Practices: Deprecation practices").
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{@a breaking-changes}
|
|
||||||
### New Breaking Changes
|
|
||||||
|
|
||||||
- Angular now compiles with Ivy by default. See the [Ivy compatibility section](#ivy).
|
|
||||||
|
|
||||||
- CLI apps compile in [AOT mode](/guide/aot-compiler) by default (which includes template type-checking).
|
|
||||||
Users who only built with JIT before may see new type errors.
|
|
||||||
See our [template type-checking guide](guide/template-typecheck) for more information and debugging tips.
|
|
||||||
|
|
||||||
- Typescript 3.4 and 3.5 are no longer supported. Please update to Typescript 3.7.
|
|
||||||
|
|
||||||
- `tslib` is now listed as a peer dependency rather than a direct dependency. If you are not using the CLI, you must manually install `tslib`, using `yarn add tslib` or `npm install tslib --save`.
|
|
||||||
|
|
||||||
{@a deprecations}
|
|
||||||
### New Deprecations
|
|
||||||
|
|
||||||
| API | Replacement | Notes |
|
|
||||||
| ------------------------------------------------------------------------| ------------------------------------ | ----- |
|
|
||||||
| [`entryComponents`](api/core/NgModule#entryComponents) | none | See [`entryComponents`](guide/deprecations#entryComponents) |
|
|
||||||
| [`CurrencyPipe` - `DEFAULT_CURRENCY_CODE`](api/common/CurrencyPipe#currency-code-deprecation)| `{provide: DEFAULT_CURRENCY_CODE, useValue: 'USD'}` | From v11 the default code will be extracted from the locale data given by `LOCAL_ID`, rather than `USD`. |
|
|
||||||
| [`ANALYZE_FOR_ENTRY_COMPONENTS`](api/core/ANALYZE_FOR_ENTRY_COMPONENTS) | none | See [`ANALYZE_FOR_ENTRY_COMPONENTS`](guide/deprecations#entryComponents) |
|
|
||||||
| `ModuleWithProviders` without a generic | `ModuleWithProviders` with a generic | |
|
|
||||||
| Undecorated base classes that use Angular features | Base classes with `@Directive()` decorator that use Angular features | |
|
|
||||||
| `esm5` and `fesm5` distribution in `@angular/*` npm packages | `esm2015` and `fesm2015` entrypoints | See [`esm5` and `fesm5`](guide/deprecations#esm5-fesm5) |
|
|
||||||
| [`TestBed.get`](api/core/testing/TestBed#get) | [`TestBed.inject`](api/core/testing/TestBed#inject) | Same behavior, but type safe. |
|
|
||||||
|
|
||||||
|
|
||||||
{@a removals}
|
|
||||||
### New Removals of Deprecated APIs
|
|
||||||
|
|
||||||
| Package | API | Replacement | Notes |
|
|
||||||
| ------- | -------------- | ----------- | ----- |
|
|
||||||
| `@angular/core` | [`Renderer`](https://v8.angular.io/api/core/Renderer) | [`Renderer2`](api/core/Renderer2) | [Migration guide.](guide/migration-renderer) |
|
|
||||||
| `@angular/core` | [`RootRenderer`](https://v8.angular.io/api/core/RootRenderer) | [`RendererFactory2`](api/core/RendererFactory2) | none |
|
|
||||||
| `@angular/core` | [`RenderComponentType`](https://v8.angular.io/api/core/RenderComponentType) | [`RendererType2`](api/core/RendererType2) | none |
|
|
||||||
| `@angular/core` | [`WtfScopeFn`](https://v8.angular.io/api/core/WtfScopeFn) | none | v8 | See [Web Tracing Framework](#wtf) |
|
|
||||||
| `@angular/core` | [`wtfCreateScope`](https://v8.angular.io/api/core/wtfCreateScope) | none | v8 | See [Web Tracing Framework](guide/deprecations#wtf) |
|
|
||||||
| `@angular/core` | [`wtfStartTimeRange`](https://v8.angular.io/api/core/wtfStartTimeRange) | none | v8 | See [Web Tracing Framework](guide/deprecations#wtf) |
|
|
||||||
| `@angular/core` | [`wtfEndTimeRange`](https://v8.angular.io/api/core/wtfEndTimeRange) | none | v8 | See [Web Tracing Framework](guide/deprecations#wtf) |
|
|
||||||
| `@angular/core` | [`wtfLeave`](https://v8.angular.io/api/core/wtfLeave) | none | v8 | See [Web Tracing Framework](guide/deprecations#wtf) |
|
|
||||||
| `@angular/common` | `DeprecatedI18NPipesModule` | [`CommonModule`](api/common/CommonModule#pipes) | none |
|
|
||||||
| `@angular/common` | `DeprecatedCurrencyPipe` | [`CurrencyPipe`](api/common/CurrencyPipe) | none |
|
|
||||||
| `@angular/common` | `DeprecatedDatePipe` | [`DatePipe`](api/common/DatePipe) | none |
|
|
||||||
| `@angular/common` | `DeprecatedDecimalPipe` | [`DecimalPipe`](api/common/DecimalPipe) | none |
|
|
||||||
| `@angular/common` | `DeprecatedPercentPipe` | [`PercentPipe`](api/common/PercentPipe) | none |
|
|
||||||
| `@angular/forms` | [`NgFormSelectorWarning`](https://v8.angular.io/api/forms/NgFormSelectorWarning) | none |
|
|
||||||
| `@angular/forms` | `ngForm` element selector | `ng-form` element selector | none |
|
|
||||||
| `@angular/service-worker` | `versionedFiles` | `files` | In the service worker configuration file `ngsw-config.json`, replace `versionedFiles` with `files`. See [Service Worker Configuration](guide/service-worker-config#assetgroups). |
|
|
||||||
|
|
||||||
{@a ivy}
|
|
||||||
|
|
||||||
## Ivy features and compatibility
|
|
||||||
|
|
||||||
In Version 9, Angular Ivy is the default rendering engine. If you haven't heard of Ivy, you can read more about it in the [Angular Ivy guide](guide/ivy).
|
|
||||||
|
|
||||||
* Among other features, Ivy introduces more comprehensive type-checking within templates. For details, see [Template Type-checking](guide/template-typecheck).
|
|
||||||
|
|
||||||
* For general guidance on debugging and a list of minor changes associated with Ivy, see the [Ivy compatibility guide](guide/ivy-compatibility).
|
|
||||||
|
|
||||||
* For help with opting out of Ivy, see the instructions [here](guide/ivy#opting-out-of-angular-ivy).
|
|
||||||
|
|
||||||
{@a migrations}
|
|
||||||
## Automated Migrations for Version 9
|
|
||||||
|
|
||||||
Read about the migrations the CLI handles for you automatically:
|
|
||||||
|
|
||||||
- [Migrating from `Renderer` to `Renderer2`](guide/migration-renderer)
|
|
||||||
- [Migrating missing `@Directive()`/`@Component()` decorators](guide/migration-undecorated-classes)
|
|
||||||
- [Migrating missing `@Injectable()` decorators and incomplete provider definitions](guide/migration-injectable)
|
|
||||||
- [Migrating dynamic queries](guide/migration-dynamic-flag)
|
|
||||||
- [Migrating to the new `$localize` i18n support](guide/migration-localize)
|
|
||||||
- [Migrating `ModuleWithProviders`](guide/migration-module-with-providers)
|
|
@ -308,7 +308,7 @@ So when IE is refreshed (manually or automatically by `ng serve`), sometimes the
|
|||||||
|
|
||||||
## Appendix: Test using `fakeAsync()/async()`
|
## Appendix: Test using `fakeAsync()/async()`
|
||||||
|
|
||||||
If you use the `fakeAsync()/async()` helper function to run unit tests (for details, read the [Testing guide](guide/testing#async-test-with-fakeasync)), you need to import `zone.js/dist/zone-testing` in your test setup file.
|
If you use the `fakeAsync()/async()` helper function to run unit tests (for details, read the [Testing guide](guide/testing-components-scenarios#fake-async)), you need to import `zone.js/dist/zone-testing` in your test setup file.
|
||||||
|
|
||||||
<div class="alert is-important">
|
<div class="alert is-important">
|
||||||
If you create project with `Angular/CLI`, it is already imported in `src/test.ts`.
|
If you create project with `Angular/CLI`, it is already imported in `src/test.ts`.
|
||||||
|
@ -41,6 +41,11 @@ When you create a library project with `ng generate library`, the library projec
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
## Strict mode
|
||||||
|
|
||||||
|
When you create new workspaces and projects, you have the option to use Angular's strict mode, which can help you write better, more maintainable code.
|
||||||
|
For more information, see [Strict mode](/guide/strict-mode).
|
||||||
|
|
||||||
## Project configuration options
|
## Project configuration options
|
||||||
|
|
||||||
The following top-level configuration properties are available for each project, under `projects:<project_name>`.
|
The following top-level configuration properties are available for each project, under `projects:<project_name>`.
|
||||||
|
BIN
aio/content/images/bios/ahasall.jpg
Normal file
BIN
aio/content/images/bios/ahasall.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
Binary file not shown.
Before Width: | Height: | Size: 17 KiB |
BIN
aio/content/images/bios/sonukapoor.jpg
Normal file
BIN
aio/content/images/bios/sonukapoor.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
3
aio/content/images/guide/providers/any-provider.svg
Normal file
3
aio/content/images/guide/providers/any-provider.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 9.6 KiB |
@ -204,7 +204,7 @@
|
|||||||
"name": "Alyssa Nicoll",
|
"name": "Alyssa Nicoll",
|
||||||
"picture": "alyssa.jpg",
|
"picture": "alyssa.jpg",
|
||||||
"twitter": "alyssanicoll",
|
"twitter": "alyssanicoll",
|
||||||
"website": "alyssa.io",
|
"website": "http://alyssa.io",
|
||||||
"bio": "Alyssa is an Angular Developer Advocate for KUI and a GDE. Her two degrees (Web Design & Development and Psychology) feed her speaking career. She has spoken at over 35 conferences internationally. She is a weekly panelist on Adventures in Angular and Angular Air, which have a combined following of over 16,000 listeners. She enjoys gaming, scuba diving, and has a newborn that fondly goes by 'Mr. Milks'.",
|
"bio": "Alyssa is an Angular Developer Advocate for KUI and a GDE. Her two degrees (Web Design & Development and Psychology) feed her speaking career. She has spoken at over 35 conferences internationally. She is a weekly panelist on Adventures in Angular and Angular Air, which have a combined following of over 16,000 listeners. She enjoys gaming, scuba diving, and has a newborn that fondly goes by 'Mr. Milks'.",
|
||||||
"groups": ["GDE"]
|
"groups": ["GDE"]
|
||||||
},
|
},
|
||||||
@ -228,7 +228,7 @@
|
|||||||
"name": "Christoffer Noring",
|
"name": "Christoffer Noring",
|
||||||
"picture": "chrisnoring.jpg",
|
"picture": "chrisnoring.jpg",
|
||||||
"twitter": "chris_noring",
|
"twitter": "chris_noring",
|
||||||
"website": "softchris.github.io",
|
"website": "https://softchris.github.io",
|
||||||
"bio": "Chris is a Full Stack Developer at McKinsey. A Google Developer Expert in Web Technologies and Angular. He is also a Nativescript Developer Expert. He is one of the organizers of the Angular conference ngVikings and an author of the book RxJS 5 Ultimate",
|
"bio": "Chris is a Full Stack Developer at McKinsey. A Google Developer Expert in Web Technologies and Angular. He is also a Nativescript Developer Expert. He is one of the organizers of the Angular conference ngVikings and an author of the book RxJS 5 Ultimate",
|
||||||
"groups": ["GDE"]
|
"groups": ["GDE"]
|
||||||
},
|
},
|
||||||
@ -596,6 +596,13 @@
|
|||||||
"twitter": "devjoost",
|
"twitter": "devjoost",
|
||||||
"bio": "Joost is a Software Engineer from the Netherlands with an interest in open source software who likes to learn something new every day. He works at Blueriq during the day and contributes to Angular in his spare time, by working on the Angular compiler and runtime. He may review your PR even if you never asked for it ;)"
|
"bio": "Joost is a Software Engineer from the Netherlands with an interest in open source software who likes to learn something new every day. He works at Blueriq during the day and contributes to Angular in his spare time, by working on the Angular compiler and runtime. He may review your PR even if you never asked for it ;)"
|
||||||
},
|
},
|
||||||
|
"sonukapoor": {
|
||||||
|
"name": "Sonu Kapoor",
|
||||||
|
"groups": ["Collaborators"],
|
||||||
|
"picture": "sonukapoor.jpg",
|
||||||
|
"website": "https://www.linkedin.com/in/sonu-kapoor/",
|
||||||
|
"bio": "Sonu is a Software Engineer from Toronto, with a high interest in front-end technologies and algorithms."
|
||||||
|
},
|
||||||
"jschwarty": {
|
"jschwarty": {
|
||||||
"name": "Justin Schwartzenberger",
|
"name": "Justin Schwartzenberger",
|
||||||
"picture": "justinschwartzenberger.jpg",
|
"picture": "justinschwartzenberger.jpg",
|
||||||
@ -655,12 +662,6 @@
|
|||||||
"picture": "bonnie.jpg",
|
"picture": "bonnie.jpg",
|
||||||
"bio": "Bonnie has been specializing in Angular since 2013. She is the founder of ngHouston Angular Meetup and a regular panelist on Angular Air. She is also the very proud parent component of @thelittlestdev!"
|
"bio": "Bonnie has been specializing in Angular since 2013. She is the founder of ngHouston Angular Meetup and a regular panelist on Angular Air. She is also the very proud parent component of @thelittlestdev!"
|
||||||
},
|
},
|
||||||
"globegitter": {
|
|
||||||
"name": "Markus Padourek",
|
|
||||||
"groups": ["Collaborators"],
|
|
||||||
"mentor": "gregmagolan",
|
|
||||||
"picture": "globegitter.jpg"
|
|
||||||
},
|
|
||||||
"ahsanayaz": {
|
"ahsanayaz": {
|
||||||
"name": "Muhammad Ahsan Ayaz",
|
"name": "Muhammad Ahsan Ayaz",
|
||||||
"picture": "ahsanayaz.jpg",
|
"picture": "ahsanayaz.jpg",
|
||||||
@ -815,5 +816,13 @@
|
|||||||
"website": "https://wellwind.idv.tw/blog/",
|
"website": "https://wellwind.idv.tw/blog/",
|
||||||
"bio": "Mike is a full-stack developer, consultant, blogger, instructor, and conference speaker. He has over 10 years of web development experience and passion to share his knowledge.",
|
"bio": "Mike is a full-stack developer, consultant, blogger, instructor, and conference speaker. He has over 10 years of web development experience and passion to share his knowledge.",
|
||||||
"groups": ["GDE"]
|
"groups": ["GDE"]
|
||||||
|
},
|
||||||
|
"ahasall": {
|
||||||
|
"name": "Amadou Sall",
|
||||||
|
"picture": "ahasall.jpg",
|
||||||
|
"groups": ["GDE"],
|
||||||
|
"twitter": "ahasall",
|
||||||
|
"website": "https://www.amadousall.com",
|
||||||
|
"bio": "Amadou is a Frontend Software Engineer from Senegal based in France. He currently works at Air France where he helps developers build better Angular applications. Passionate about web technologies, Amadou is an international speaker, a technical writer, and a Google Developer Expert in Angular."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,6 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
|
||||||
<th><a href="https://ngvikings.org/" title="ngVikings">ngVikings</a></th>
|
|
||||||
<td>Oslo, Norway</td>
|
|
||||||
<td>May 25-26 conference, 27 workshops, 2020</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
@ -31,6 +26,12 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<!-- ng-vikings 2020 -->
|
||||||
|
<tr>
|
||||||
|
<th><a href="https://ngvikings.org/" title="ngVikings">ngVikings</a></th>
|
||||||
|
<td>Oslo, Norway</td>
|
||||||
|
<td>May 25-26 conference, 27 workshops, 2020</td>
|
||||||
|
</tr>
|
||||||
<!-- ng-conf 2020 -->
|
<!-- ng-conf 2020 -->
|
||||||
<tr>
|
<tr>
|
||||||
<th><a href="https://ng-conf.org/" title="ng-conf">ng-conf</a></th>
|
<th><a href="https://ng-conf.org/" title="ng-conf">ng-conf</a></th>
|
||||||
|
@ -97,6 +97,11 @@
|
|||||||
"Data Libraries": {
|
"Data Libraries": {
|
||||||
"order": 3,
|
"order": 3,
|
||||||
"resources": {
|
"resources": {
|
||||||
|
"formly": {
|
||||||
|
"desc": "Formly is a dynamic (JSON powered) form library, built on top of Angular Reactive Forms.",
|
||||||
|
"title": "Formly",
|
||||||
|
"url": "https://formly.dev"
|
||||||
|
},
|
||||||
"rx-web": {
|
"rx-web": {
|
||||||
"desc": "RxWeb Reactive Form Validators provides all types of complex, conditional, cross field, and dynamic validation on validator-based reactive forms, model-based reactive forms, and template driven forms.",
|
"desc": "RxWeb Reactive Form Validators provides all types of complex, conditional, cross field, and dynamic validation on validator-based reactive forms, model-based reactive forms, and template driven forms.",
|
||||||
"title": "RxWeb Reactive Form Validators",
|
"title": "RxWeb Reactive Form Validators",
|
||||||
@ -236,6 +241,12 @@
|
|||||||
"logo": "",
|
"logo": "",
|
||||||
"title": "Protractor",
|
"title": "Protractor",
|
||||||
"url": "https://protractor.angular.io/"
|
"url": "https://protractor.angular.io/"
|
||||||
|
},
|
||||||
|
"scully": {
|
||||||
|
"desc": "Scully (Jamstack Toolchain for Angular) makes building, testing, and deploying Jamstack apps extremely simple.",
|
||||||
|
"title": "Scully",
|
||||||
|
"logo": "https://raw.githubusercontent.com/scullyio/scully/main/assets/logos/PNG/Green/scullyio-logo-green.png",
|
||||||
|
"url": "https://scully.io"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -506,80 +506,6 @@
|
|||||||
"url": "guide/universal",
|
"url": "guide/universal",
|
||||||
"title": "Server-side Rendering",
|
"title": "Server-side Rendering",
|
||||||
"tooltip": "Render HTML server-side with Angular Universal."
|
"tooltip": "Render HTML server-side with Angular Universal."
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Upgrading from AngularJS",
|
|
||||||
"tooltip": "Incrementally upgrade an AngularJS application to Angular.",
|
|
||||||
"children": [
|
|
||||||
{
|
|
||||||
"url": "guide/upgrade-setup",
|
|
||||||
"title": "Setup for Upgrading from AngularJS",
|
|
||||||
"tooltip": "Use code from the Angular QuickStart seed as part of upgrading from AngularJS.",
|
|
||||||
"hidden": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "guide/upgrade",
|
|
||||||
"title": "Upgrading Instructions",
|
|
||||||
"tooltip": "Incrementally upgrade an AngularJS application to Angular."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "guide/upgrade-performance",
|
|
||||||
"title": "Upgrading for Performance",
|
|
||||||
"tooltip": "Upgrade from AngularJS to Angular in a more flexible way."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "guide/ajs-quick-reference",
|
|
||||||
"title": "AngularJS-Angular Concepts",
|
|
||||||
"tooltip": "Learn how AngularJS concepts and techniques map to Angular."
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Angular Libraries",
|
|
||||||
"tooltip": "Extending Angular with shared libraries.",
|
|
||||||
"children": [
|
|
||||||
{
|
|
||||||
"url": "guide/libraries",
|
|
||||||
"title": "Libraries Overview",
|
|
||||||
"tooltip": "Understand how and when to use or create libraries."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "guide/using-libraries",
|
|
||||||
"title": "Using Published Libraries",
|
|
||||||
"tooltip": "Integrate published libraries into an app."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "guide/creating-libraries",
|
|
||||||
"title": "Creating Libraries",
|
|
||||||
"tooltip": "Extend Angular by creating, publishing, and using your own libraries."
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Schematics",
|
|
||||||
"tooltip": "Using CLI schematics for code generation.",
|
|
||||||
"children": [
|
|
||||||
{
|
|
||||||
"url": "guide/schematics",
|
|
||||||
"title": "Schematics Overview",
|
|
||||||
"tooltip": "How the CLI uses schematics to generate code."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "guide/schematics-authoring",
|
|
||||||
"title": "Authoring Schematics",
|
|
||||||
"tooltip": "Understand the structure of a schematic."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "guide/schematics-for-libraries",
|
|
||||||
"title": "Schematics for Libraries",
|
|
||||||
"tooltip": "Use schematics to integrate your library with the Angular CLI."
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "guide/cli-builder",
|
|
||||||
"title": "CLI Builders",
|
|
||||||
"tooltip": "Using builders to customize Angular CLI."
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -600,28 +526,74 @@
|
|||||||
"url": "guide/angular-compiler-options",
|
"url": "guide/angular-compiler-options",
|
||||||
"title": "Angular Compiler Options",
|
"title": "Angular Compiler Options",
|
||||||
"tooltip": "Configuring AOT compilation."
|
"tooltip": "Configuring AOT compilation."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "guide/aot-metadata-errors",
|
"url": "guide/aot-metadata-errors",
|
||||||
"title": "AOT Metadata Errors",
|
"title": "AOT Metadata Errors",
|
||||||
"tooltip": "Troubleshooting AOT compilation."
|
"tooltip": "Troubleshooting AOT compilation."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "guide/template-typecheck",
|
"url": "guide/template-typecheck",
|
||||||
"title": "Template Type-checking",
|
"title": "Template Type-checking",
|
||||||
"tooltip": "Template type-checking in Angular."
|
"tooltip": "Template type-checking in Angular."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "guide/build",
|
"url": "guide/build",
|
||||||
"title": "Building & Serving",
|
"title": "Building & Serving",
|
||||||
"tooltip": "Building and serving Angular apps."
|
"tooltip": "Building and serving Angular apps."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "guide/testing",
|
|
||||||
"title": "Testing",
|
"title": "Testing",
|
||||||
"tooltip": "Techniques and practices for testing an Angular app."
|
"tooltip": "Testing your Angular apps.",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"url": "guide/testing",
|
||||||
|
"title": "Intro to Testing",
|
||||||
|
"tooltip": "Introduction to testing an Angular app."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "guide/testing-code-coverage",
|
||||||
|
"title": "Code Coverage",
|
||||||
|
"tooltip": "Determine how much of your code is tested."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "guide/testing-services",
|
||||||
|
"title": "Testing Services",
|
||||||
|
"tooltip": "How to test services."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "guide/testing-components-basics",
|
||||||
|
"title": "Basics of Testing Components",
|
||||||
|
"tooltip": "The fundamentals of how to test components."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "guide/testing-components-scenarios",
|
||||||
|
"title": "Component Testing Scenarios",
|
||||||
|
"tooltip": "Use cases for testing components."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "guide/testing-attribute-directives",
|
||||||
|
"title": "Testing Attribute Directives",
|
||||||
|
"tooltip": "How to test attribute directives."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "guide/testing-pipes",
|
||||||
|
"title": "Testing Pipes",
|
||||||
|
"tooltip": "Writing tests for pipes."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "guide/test-debugging",
|
||||||
|
"title": "Debugging Tests",
|
||||||
|
"tooltip": "How to debug tests."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "guide/testing-utility-apis",
|
||||||
|
"title": "Testing Utility APIs",
|
||||||
|
"tooltip": "Features of the Angular testing utilities."
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "guide/deployment",
|
"url": "guide/deployment",
|
||||||
@ -675,6 +647,11 @@
|
|||||||
"url": "guide/browser-support",
|
"url": "guide/browser-support",
|
||||||
"title": "Browser Support",
|
"title": "Browser Support",
|
||||||
"tooltip": "Browser support and polyfills guide."
|
"tooltip": "Browser support and polyfills guide."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "guide/strict-mode",
|
||||||
|
"title": "Strict mode",
|
||||||
|
"tooltip": "Reference documentation for Angular's strict mode."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -736,9 +713,20 @@
|
|||||||
"tooltip": "End-to-end tutorials for learning Angular concepts and patterns.",
|
"tooltip": "End-to-end tutorials for learning Angular concepts and patterns.",
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"url": "guide/router-tutorial",
|
"title": "Routing",
|
||||||
"title": "Using Angular Routes in a Single-page Application",
|
"tooltip": "End-to-end tutorials for learning about Angular's router.",
|
||||||
"tooltip": "A tutorial that covers many patterns associated with Angular routing."
|
"children": [
|
||||||
|
{
|
||||||
|
"url": "guide/router-tutorial",
|
||||||
|
"title": "Using Angular Routes in a Single-page Application",
|
||||||
|
"tooltip": "A tutorial that covers many patterns associated with Angular routing."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "guide/router-tutorial-toh",
|
||||||
|
"title": "Router tutorial: tour of heroes",
|
||||||
|
"tooltip": "Explore how to use Angular's router. Based on the Tour of Heroes example."
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "guide/forms",
|
"url": "guide/forms",
|
||||||
@ -762,13 +750,13 @@
|
|||||||
"tooltip": "Angular versioning, release, support, and deprecation policies and practices."
|
"tooltip": "Angular versioning, release, support, and deprecation policies and practices."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "Updating to Version 9",
|
"title": "Updating to Version 10",
|
||||||
"tooltip": "Support for updating your application from version 8 to 9.",
|
"tooltip": "Support for updating your application from version 9 to 10.",
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"url": "guide/updating-to-version-9",
|
"url": "guide/updating-to-version-10",
|
||||||
"title": "Overview",
|
"title": "Overview",
|
||||||
"tooltip": "Everything you need to know for updating your application from version 8 to 9."
|
"tooltip": "Everything you need to know for updating your application from version 9 to 10."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": "guide/ivy-compatibility",
|
"url": "guide/ivy-compatibility",
|
||||||
@ -776,29 +764,9 @@
|
|||||||
"tooltip": "Details to help you make sure your application is compatible with Ivy."
|
"tooltip": "Details to help you make sure your application is compatible with Ivy."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"title": "Optional Migrations",
|
"title": "Migrations",
|
||||||
"tooltip": "Optional migration details regarding updating to version 9.",
|
"tooltip": "Migration details regarding updating to version 10.",
|
||||||
"children": [
|
"children": [
|
||||||
{
|
|
||||||
"url": "guide/migration-renderer",
|
|
||||||
"title": "Renderer to Renderer2",
|
|
||||||
"tooltip": "Migration from the deprecated Renderer API to the newer Renderer2 API."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "guide/migration-dynamic-flag",
|
|
||||||
"title": "Dynamic Queries Flag",
|
|
||||||
"tooltip": "Migration to remove unnecessary `static: false` flag from @ViewChild and @ContentChild queries."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "guide/migration-injectable",
|
|
||||||
"title": "Missing @Injectable() Decorators",
|
|
||||||
"tooltip": "Migration to add missing @Injectable() decorators and incomplete provider definitions."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "guide/migration-localize",
|
|
||||||
"title": "$localize Global Import",
|
|
||||||
"tooltip": "Migration to add an import statement for @angular/localize to polyfills.ts."
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"url": "guide/migration-module-with-providers",
|
"url": "guide/migration-module-with-providers",
|
||||||
"title": "Missing ModuleWithProviders Generic",
|
"title": "Missing ModuleWithProviders Generic",
|
||||||
@ -808,6 +776,26 @@
|
|||||||
"url": "guide/migration-undecorated-classes",
|
"url": "guide/migration-undecorated-classes",
|
||||||
"title": "Missing @Directive() Decorators",
|
"title": "Missing @Directive() Decorators",
|
||||||
"tooltip": "Migration to add missing @Directive()/@Component() decorators."
|
"tooltip": "Migration to add missing @Directive()/@Component() decorators."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "guide/migration-injectable",
|
||||||
|
"title": "Missing @Injectable() Decorators",
|
||||||
|
"tooltip": "Migration to add missing @Injectable() decorators and incomplete provider definitions."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "guide/migration-solution-style-tsconfig",
|
||||||
|
"title": "Solution-style `tsconfig.json`",
|
||||||
|
"tooltip": "Migration to create a solution-style `tsconfig.json`."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "guide/migration-update-libraries-tslib",
|
||||||
|
"title": "`tslib` direct dependency",
|
||||||
|
"tooltip": "Migration to a direct dependency on the `tslib` npm package."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "guide/migration-update-module-and-target-compiler-options",
|
||||||
|
"title": "`module` and `target` compiler options",
|
||||||
|
"tooltip": "Migration to update `module` and `target` compiler options."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -1003,6 +991,10 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"docVersions": [
|
"docVersions": [
|
||||||
|
{
|
||||||
|
"title": "v9",
|
||||||
|
"url": "https://v9.angular.io/"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"title": "v8",
|
"title": "v8",
|
||||||
"url": "https://v8.angular.io/"
|
"url": "https://v8.angular.io/"
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
In this tutorial, you build your own app from the ground up, providing experience with the typical development process, as well as an introduction to basic app-design concepts, tools, and terminology.
|
In this tutorial, you build your own app from the ground up, providing experience with the typical development process, as well as an introduction to basic app-design concepts, tools, and terminology.
|
||||||
|
|
||||||
If you're completely new to Angular, you might want to try the [**Try it now**](start) quick-start app first.
|
If you're completely new to Angular, you might want to try the [**Try it now**](start) quick-start app first.
|
||||||
It is based on a ready-made partially-completed project, which you can examine and modify in the StacBlitz interactive development environment, where you can see the results in real time.
|
It is based on a ready-made partially-completed project, which you can examine and modify in the StackBlitz interactive development environment, where you can see the results in real time.
|
||||||
|
|
||||||
The "Try it" tutorial covers the same major topics—components, template syntax, routing, services, and accessing data via HTTP—in a condensed format, following the most current best practices.
|
The "Try it" tutorial covers the same major topics—components, template syntax, routing, services, and accessing data via HTTP—in a condensed format, following the most current best practices.
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ sets the `heroService` parameter to the singleton instance of `HeroService`.
|
|||||||
|
|
||||||
### Add `getHeroes()`
|
### Add `getHeroes()`
|
||||||
|
|
||||||
Create a function to retrieve the heroes from the service.
|
Create a method to retrieve the heroes from the service.
|
||||||
|
|
||||||
<code-example path="toh-pt4/src/app/heroes/heroes.component.1.ts" header="src/app/heroes/heroes.component.ts" region="getHeroes">
|
<code-example path="toh-pt4/src/app/heroes/heroes.component.1.ts" header="src/app/heroes/heroes.component.ts" region="getHeroes">
|
||||||
</code-example>
|
</code-example>
|
||||||
|
@ -79,7 +79,8 @@ Replace the default contents of `in-memory-data.service.ts` with the following:
|
|||||||
|
|
||||||
<code-example path="toh-pt6/src/app/in-memory-data.service.ts" region="init" header="src/app/in-memory-data.service.ts"></code-example>
|
<code-example path="toh-pt6/src/app/in-memory-data.service.ts" region="init" header="src/app/in-memory-data.service.ts"></code-example>
|
||||||
|
|
||||||
The `in-memory-data.service.ts` file replaces `mock-heroes.ts`, which is now safe to delete.
|
The `in-memory-data.service.ts` file will take over the function of `mock-heroes.ts`.
|
||||||
|
However, don't delete `mock-heroes.ts` yet, as you still need it for a few more steps of this tutorial.
|
||||||
|
|
||||||
When the server is ready, you'll detach the In-memory Web API, and the app's requests will go through to the server.
|
When the server is ready, you'll detach the In-memory Web API, and the app's requests will go through to the server.
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"hosting": {
|
"hosting": {
|
||||||
|
"target": "aio",
|
||||||
"public": "dist",
|
"public": "dist",
|
||||||
"cleanUrls": true,
|
"cleanUrls": true,
|
||||||
"redirects": [
|
"redirects": [
|
||||||
@ -122,7 +123,12 @@
|
|||||||
// Strip off the `.html` extension, because Firebase will not do this automatically any more
|
// Strip off the `.html` extension, because Firebase will not do this automatically any more
|
||||||
// (unless the new URL points to an existing file, which is not necessarily the case here).
|
// (unless the new URL points to an existing file, which is not necessarily the case here).
|
||||||
{"type": 301, "source": "/:somePath*/:file.html", "destination": "/:somePath*/:file"},
|
{"type": 301, "source": "/:somePath*/:file.html", "destination": "/:somePath*/:file"},
|
||||||
{"type": 301, "source": "/:topLevelFile.html", "destination": "/:topLevelFile"}
|
{"type": 301, "source": "/:topLevelFile.html", "destination": "/:topLevelFile"},
|
||||||
|
|
||||||
|
// The below paths are referenced in users projects generated by the CLI
|
||||||
|
{"type": 301, "source": "/config/tsconfig", "destination": "/guide/typescript-configuration"},
|
||||||
|
{"type": 301, "source": "/config/solution-tsconfig", "destination": "https://devblogs.microsoft.com/typescript/announcing-typescript-3-9/#solution-style-tsconfig"},
|
||||||
|
{"type": 301, "source": "/config/app-package-json", "destination": "/guide/strict-mode#non-local-side-effects-in-applications"}
|
||||||
],
|
],
|
||||||
"rewrites": [
|
"rewrites": [
|
||||||
{
|
{
|
||||||
|
@ -147,6 +147,7 @@
|
|||||||
"!/styleguide",
|
"!/styleguide",
|
||||||
"!/styleguide/**",
|
"!/styleguide/**",
|
||||||
"!/testing",
|
"!/testing",
|
||||||
"!/testing/**"
|
"!/testing/**",
|
||||||
|
"!/config/**"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -87,28 +87,28 @@
|
|||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@angular/animations": "10.0.0-rc.2",
|
"@angular/animations": "10.0.2",
|
||||||
"@angular/cdk": "^9.2.2",
|
"@angular/cdk": "10.0.1",
|
||||||
"@angular/common": "10.0.0-rc.2",
|
"@angular/common": "10.0.2",
|
||||||
"@angular/compiler": "10.0.0-rc.2",
|
"@angular/compiler": "10.0.2",
|
||||||
"@angular/core": "10.0.0-rc.2",
|
"@angular/core": "10.0.2",
|
||||||
"@angular/elements": "10.0.0-rc.2",
|
"@angular/elements": "10.0.2",
|
||||||
"@angular/forms": "10.0.0-rc.2",
|
"@angular/forms": "10.0.2",
|
||||||
"@angular/material": "^9.2.2",
|
"@angular/material": "10.0.1",
|
||||||
"@angular/platform-browser": "10.0.0-rc.2",
|
"@angular/platform-browser": "10.0.2",
|
||||||
"@angular/platform-browser-dynamic": "10.0.0-rc.2",
|
"@angular/platform-browser-dynamic": "10.0.2",
|
||||||
"@angular/router": "10.0.0-rc.2",
|
"@angular/router": "10.0.2",
|
||||||
"@angular/service-worker": "10.0.0-rc.2",
|
"@angular/service-worker": "10.0.2",
|
||||||
"@webcomponents/custom-elements": "1.2.1",
|
"@webcomponents/custom-elements": "1.2.1",
|
||||||
"rxjs": "^6.5.3",
|
"rxjs": "^6.5.3",
|
||||||
"tslib": "^1.10.0",
|
"tslib": "^1.10.0",
|
||||||
"zone.js": "~0.10.3"
|
"zone.js": "~0.10.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@angular-devkit/build-angular": "0.1000.0-rc.2",
|
"@angular-devkit/build-angular": "0.1000.1",
|
||||||
"@angular/cli": "10.0.0-rc.2",
|
"@angular/cli": "10.0.1",
|
||||||
"@angular/compiler-cli": "10.0.0-rc.2",
|
"@angular/compiler-cli": "10.0.2",
|
||||||
"@angular/language-service": "10.0.0-rc.2",
|
"@angular/language-service": "10.0.2",
|
||||||
"@types/jasmine": "^3.4.2",
|
"@types/jasmine": "^3.4.2",
|
||||||
"@types/jasminewd2": "^2.0.8",
|
"@types/jasminewd2": "^2.0.8",
|
||||||
"@types/lunr": "^2.3.2",
|
"@types/lunr": "^2.3.2",
|
||||||
@ -123,7 +123,7 @@
|
|||||||
"cross-spawn": "^5.1.0",
|
"cross-spawn": "^5.1.0",
|
||||||
"css-selector-parser": "^1.3.0",
|
"css-selector-parser": "^1.3.0",
|
||||||
"dgeni": "^0.4.11",
|
"dgeni": "^0.4.11",
|
||||||
"dgeni-packages": "^0.28.3",
|
"dgeni-packages": "^0.28.4",
|
||||||
"entities": "^1.1.1",
|
"entities": "^1.1.1",
|
||||||
"eslint": "^3.19.0",
|
"eslint": "^3.19.0",
|
||||||
"eslint-plugin-jasmine": "^2.2.0",
|
"eslint-plugin-jasmine": "^2.2.0",
|
||||||
@ -175,4 +175,4 @@
|
|||||||
"xregexp": "^4.0.0",
|
"xregexp": "^4.0.0",
|
||||||
"yargs": "^7.0.2"
|
"yargs": "^7.0.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ else
|
|||||||
readonly majorVersionStable=${CI_STABLE_BRANCH%%.*}
|
readonly majorVersionStable=${CI_STABLE_BRANCH%%.*}
|
||||||
|
|
||||||
# Do not deploy if the major version is not less than the stable branch major version
|
# Do not deploy if the major version is not less than the stable branch major version
|
||||||
if [[ !( "$majorVersion" -lt "$majorVersionStable" ) ]]; then
|
if (( $majorVersion >= $majorVersionStable )); then
|
||||||
echo "Skipping deploy of branch \"$CI_BRANCH\" to firebase."
|
echo "Skipping deploy of branch \"$CI_BRANCH\" to firebase."
|
||||||
echo "We only deploy archive branches with the major version less than the stable branch: \"$CI_STABLE_BRANCH\""
|
echo "We only deploy archive branches with the major version less than the stable branch: \"$CI_STABLE_BRANCH\""
|
||||||
exit 0
|
exit 0
|
||||||
@ -64,16 +64,27 @@ fi
|
|||||||
case $deployEnv in
|
case $deployEnv in
|
||||||
next)
|
next)
|
||||||
readonly projectId=aio-staging
|
readonly projectId=aio-staging
|
||||||
|
readonly siteId=$projectId
|
||||||
readonly deployedUrl=https://next.angular.io/
|
readonly deployedUrl=https://next.angular.io/
|
||||||
readonly firebaseToken=$CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN
|
readonly firebaseToken=$CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN
|
||||||
;;
|
;;
|
||||||
stable)
|
stable)
|
||||||
readonly projectId=angular-io
|
readonly projectId=angular-io
|
||||||
|
readonly siteId=$projectId
|
||||||
readonly deployedUrl=https://angular.io/
|
readonly deployedUrl=https://angular.io/
|
||||||
readonly firebaseToken=$CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN
|
readonly firebaseToken=$CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN
|
||||||
;;
|
;;
|
||||||
archive)
|
archive)
|
||||||
readonly projectId=v${majorVersion}-angular-io
|
# Special case v9-angular-io because its piloting the firebase hosting "multisites" setup
|
||||||
|
# See https://angular-team.atlassian.net/browse/DEV-125 for more info.
|
||||||
|
if [[ "$majorVersion" == "9" ]]; then
|
||||||
|
readonly projectId=aio-staging
|
||||||
|
readonly siteId=v9-angular-io
|
||||||
|
else
|
||||||
|
readonly projectId=v${majorVersion}-angular-io
|
||||||
|
readonly siteId=$projectId
|
||||||
|
fi
|
||||||
|
|
||||||
readonly deployedUrl=https://v${majorVersion}.angular.io/
|
readonly deployedUrl=https://v${majorVersion}.angular.io/
|
||||||
readonly firebaseToken=$CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN
|
readonly firebaseToken=$CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN
|
||||||
;;
|
;;
|
||||||
@ -82,6 +93,7 @@ esac
|
|||||||
echo "Git branch : $CI_BRANCH"
|
echo "Git branch : $CI_BRANCH"
|
||||||
echo "Build/deploy mode : $deployEnv"
|
echo "Build/deploy mode : $deployEnv"
|
||||||
echo "Firebase project : $projectId"
|
echo "Firebase project : $projectId"
|
||||||
|
echo "Firebase site : $siteId"
|
||||||
echo "Deployment URL : $deployedUrl"
|
echo "Deployment URL : $deployedUrl"
|
||||||
|
|
||||||
if [[ ${1:-} == "--dry-run" ]]; then
|
if [[ ${1:-} == "--dry-run" ]]; then
|
||||||
@ -92,23 +104,29 @@ fi
|
|||||||
(
|
(
|
||||||
cd "`dirname $0`/.."
|
cd "`dirname $0`/.."
|
||||||
|
|
||||||
# Build the app
|
echo "\n\n\n==== Build the aio app ====\n"
|
||||||
yarn build --configuration=$deployEnv --progress=false
|
yarn build --configuration=$deployEnv --progress=false
|
||||||
|
|
||||||
# Include any mode-specific files
|
|
||||||
|
echo "\n\n\n==== Add any mode-specific files into the aio distribution ====\n"
|
||||||
cp -rf src/extra-files/$deployEnv/. dist/
|
cp -rf src/extra-files/$deployEnv/. dist/
|
||||||
|
|
||||||
# Set deployedUrl as parameter in the opensearch description
|
|
||||||
|
echo "\n\n\n==== Update opensearch descriptor for aio with the deployedUrl ====\n"
|
||||||
# deployedUrl must end with /
|
# deployedUrl must end with /
|
||||||
yarn set-opensearch-url $deployedUrl
|
yarn set-opensearch-url $deployedUrl
|
||||||
|
|
||||||
# Check payload size
|
echo "\n\n\n==== Check payload size and upload the numbers to firebase db ====\n"
|
||||||
yarn payload-size
|
yarn payload-size
|
||||||
|
|
||||||
# Deploy to Firebase
|
|
||||||
yarn firebase use "$projectId" --token "$firebaseToken"
|
|
||||||
yarn firebase deploy --message "Commit: $CI_COMMIT" --non-interactive --token "$firebaseToken"
|
|
||||||
|
|
||||||
# Run PWA-score tests
|
echo "\n\n\n==== Deploy aio to firebase hosting ====\n"
|
||||||
|
|
||||||
|
yarn firebase use "${projectId}" --token "$firebaseToken"
|
||||||
|
yarn firebase target:apply hosting aio $siteId --token "$firebaseToken"
|
||||||
|
yarn firebase deploy --only hosting:aio --message "Commit: $CI_COMMIT" --non-interactive --token "$firebaseToken"
|
||||||
|
|
||||||
|
|
||||||
|
echo "\n\n\n==== Run PWA-score tests ====\n"
|
||||||
yarn test-pwa-score "$deployedUrl" "$CI_AIO_MIN_PWA_SCORE"
|
yarn test-pwa-score "$deployedUrl" "$CI_AIO_MIN_PWA_SCORE"
|
||||||
)
|
)
|
||||||
|
@ -68,6 +68,7 @@ function check {
|
|||||||
expected="Git branch : master
|
expected="Git branch : master
|
||||||
Build/deploy mode : next
|
Build/deploy mode : next
|
||||||
Firebase project : aio-staging
|
Firebase project : aio-staging
|
||||||
|
Firebase site : aio-staging
|
||||||
Deployment URL : https://next.angular.io/"
|
Deployment URL : https://next.angular.io/"
|
||||||
check "$actual" "$expected"
|
check "$actual" "$expected"
|
||||||
)
|
)
|
||||||
@ -103,6 +104,7 @@ Deployment URL : https://next.angular.io/"
|
|||||||
expected="Git branch : 4.3.x
|
expected="Git branch : 4.3.x
|
||||||
Build/deploy mode : stable
|
Build/deploy mode : stable
|
||||||
Firebase project : angular-io
|
Firebase project : angular-io
|
||||||
|
Firebase site : angular-io
|
||||||
Deployment URL : https://angular.io/"
|
Deployment URL : https://angular.io/"
|
||||||
check "$actual" "$expected"
|
check "$actual" "$expected"
|
||||||
)
|
)
|
||||||
@ -139,10 +141,37 @@ Deployment URL : https://angular.io/"
|
|||||||
expected="Git branch : 2.4.x
|
expected="Git branch : 2.4.x
|
||||||
Build/deploy mode : archive
|
Build/deploy mode : archive
|
||||||
Firebase project : v2-angular-io
|
Firebase project : v2-angular-io
|
||||||
|
Firebase site : v2-angular-io
|
||||||
Deployment URL : https://v2.angular.io/"
|
Deployment URL : https://v2.angular.io/"
|
||||||
check "$actual" "$expected"
|
check "$actual" "$expected"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
(
|
||||||
|
echo ===== archive - v9-angular-io multisite special case - deploy success
|
||||||
|
actual=$(
|
||||||
|
export BASH_ENV=/dev/null
|
||||||
|
export CI_REPO_OWNER=angular
|
||||||
|
export CI_REPO_NAME=angular
|
||||||
|
export CI_PULL_REQUEST=false
|
||||||
|
export CI_BRANCH=9.1.x
|
||||||
|
export CI_STABLE_BRANCH=10.0.x
|
||||||
|
export CI_COMMIT=$(git ls-remote origin 9.1.x | cut -c1-40)
|
||||||
|
export CI_SECRET_AIO_DEPLOY_FIREBASE_TOKEN=XXXXX
|
||||||
|
$deployToFirebaseDryRun
|
||||||
|
)
|
||||||
|
expected="Git branch : 9.1.x
|
||||||
|
Build/deploy mode : archive
|
||||||
|
Firebase project : aio-staging
|
||||||
|
Firebase site : v9-angular-io
|
||||||
|
Deployment URL : https://v9.angular.io/"
|
||||||
|
# TODO: This test incorrectly expects the Firebase project to be v9-angular-io.
|
||||||
|
# v9-angular-io is a "multisites" project currently within the aio-staging project
|
||||||
|
# This setup is temporary and was created in order to deploy v9.angular.io without
|
||||||
|
# disruptions.
|
||||||
|
# See https://angular-team.atlassian.net/browse/DEV-125 for more info.
|
||||||
|
check "$actual" "$expected"
|
||||||
|
)
|
||||||
|
|
||||||
(
|
(
|
||||||
echo ===== archive - skip deploy - commit not HEAD
|
echo ===== archive - skip deploy - commit not HEAD
|
||||||
actual=$(
|
actual=$(
|
||||||
|
@ -14,11 +14,11 @@
|
|||||||
<button mat-button class="hamburger" [class.starting]="isStarting" (click)="sidenav.toggle()" title="Docs menu">
|
<button mat-button class="hamburger" [class.starting]="isStarting" (click)="sidenav.toggle()" title="Docs menu">
|
||||||
<mat-icon svgIcon="menu"></mat-icon>
|
<mat-icon svgIcon="menu"></mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<a class="nav-link home" href="/" [ngSwitch]="isSideBySide">
|
<a class="nav-link home" href="/" [ngSwitch]="showTopMenu">
|
||||||
<img *ngSwitchCase="true" src="assets/images/logos/angular/logo-nav@2x.png" width="150" height="40" title="Home" alt="Home">
|
<img *ngSwitchCase="true" src="assets/images/logos/angular/logo-nav@2x.png" width="150" height="40" title="Home" alt="Home">
|
||||||
<img *ngSwitchDefault src="assets/images/logos/angular/shield-large.svg" width="37" height="40" title="Home" alt="Home">
|
<img *ngSwitchDefault src="assets/images/logos/angular/shield-large.svg" width="37" height="40" title="Home" alt="Home">
|
||||||
</a>
|
</a>
|
||||||
<aio-top-menu *ngIf="isSideBySide" [nodes]="topMenuNodes" [currentNode]="currentNodes?.TopBar"></aio-top-menu>
|
<aio-top-menu *ngIf="showTopMenu" [nodes]="topMenuNodes" [currentNode]="currentNodes?.TopBar"></aio-top-menu>
|
||||||
<aio-search-box class="search-container" #searchBox (onSearch)="doSearch($event)" (onFocus)="doSearch($event)"></aio-search-box>
|
<aio-search-box class="search-container" #searchBox (onSearch)="doSearch($event)" (onFocus)="doSearch($event)"></aio-search-box>
|
||||||
<div class="toolbar-external-icons-container">
|
<div class="toolbar-external-icons-container">
|
||||||
<a href="https://twitter.com/angular" title="Twitter" aria-label="Angular on twitter">
|
<a href="https://twitter.com/angular" title="Twitter" aria-label="Angular on twitter">
|
||||||
@ -35,9 +35,9 @@
|
|||||||
|
|
||||||
<mat-sidenav-container class="sidenav-container" [class.starting]="isStarting" [class.has-floating-toc]="hasFloatingToc" role="main">
|
<mat-sidenav-container class="sidenav-container" [class.starting]="isStarting" [class.has-floating-toc]="hasFloatingToc" role="main">
|
||||||
|
|
||||||
<mat-sidenav [ngClass]="{'collapsed': !isSideBySide}" #sidenav class="sidenav" [mode]="mode" [opened]="isOpened" (openedChange)="updateHostClasses()">
|
<mat-sidenav [ngClass]="{'collapsed': !dockSideNav}" #sidenav class="sidenav" [mode]="mode" [opened]="isOpened" (openedChange)="updateHostClasses()">
|
||||||
<aio-nav-menu *ngIf="!isSideBySide" [nodes]="topMenuNarrowNodes" [currentNode]="currentNodes?.TopBarNarrow" [isWide]="false"></aio-nav-menu>
|
<aio-nav-menu *ngIf="!showTopMenu" [nodes]="topMenuNarrowNodes" [currentNode]="currentNodes?.TopBarNarrow" [isWide]="false"></aio-nav-menu>
|
||||||
<aio-nav-menu [nodes]="sideNavNodes" [currentNode]="currentNodes?.SideNav" [isWide]="isSideBySide"></aio-nav-menu>
|
<aio-nav-menu [nodes]="sideNavNodes" [currentNode]="currentNodes?.SideNav" [isWide]="dockSideNav"></aio-nav-menu>
|
||||||
|
|
||||||
<div class="doc-version">
|
<div class="doc-version">
|
||||||
<aio-select (change)="onDocVersionChange($event.index)" [options]="docVersions" [selected]="currentDocVersion"></aio-select>
|
<aio-select (change)="onDocVersionChange($event.index)" [options]="docVersions" [selected]="currentDocVersion"></aio-select>
|
||||||
|
@ -25,11 +25,9 @@ import { first, mapTo } from 'rxjs/operators';
|
|||||||
import { MockLocationService } from 'testing/location.service';
|
import { MockLocationService } from 'testing/location.service';
|
||||||
import { MockLogger } from 'testing/logger.service';
|
import { MockLogger } from 'testing/logger.service';
|
||||||
import { MockSearchService } from 'testing/search.service';
|
import { MockSearchService } from 'testing/search.service';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent, dockSideNavWidth, showFloatingTocWidth, showTopMenuWidth } from './app.component';
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
|
|
||||||
const sideBySideBreakPoint = 992;
|
|
||||||
const hideToCBreakPoint = 800;
|
|
||||||
const startedDelay = 100;
|
const startedDelay = 100;
|
||||||
|
|
||||||
describe('AppComponent', () => {
|
describe('AppComponent', () => {
|
||||||
@ -58,7 +56,7 @@ describe('AppComponent', () => {
|
|||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.onResize(sideBySideBreakPoint + 1); // wide by default
|
component.onResize(showTopMenuWidth + 1); // wide by default
|
||||||
|
|
||||||
const de = fixture.debugElement;
|
const de = fixture.debugElement;
|
||||||
const docViewerDe = de.query(By.css('aio-doc-viewer'));
|
const docViewerDe = de.query(By.css('aio-doc-viewer'));
|
||||||
@ -99,7 +97,7 @@ describe('AppComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be false on narrow screens', () => {
|
it('should be false on narrow screens', () => {
|
||||||
component.onResize(hideToCBreakPoint - 1);
|
component.onResize(showFloatingTocWidth - 1);
|
||||||
|
|
||||||
tocService.tocList.next([{}, {}, {}] as TocItem[]);
|
tocService.tocList.next([{}, {}, {}] as TocItem[]);
|
||||||
expect(component.hasFloatingToc).toBe(false);
|
expect(component.hasFloatingToc).toBe(false);
|
||||||
@ -112,7 +110,7 @@ describe('AppComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be true on wide screens unless the toc is empty', () => {
|
it('should be true on wide screens unless the toc is empty', () => {
|
||||||
component.onResize(hideToCBreakPoint + 1);
|
component.onResize(showFloatingTocWidth + 1);
|
||||||
|
|
||||||
tocService.tocList.next([{}, {}, {}] as TocItem[]);
|
tocService.tocList.next([{}, {}, {}] as TocItem[]);
|
||||||
expect(component.hasFloatingToc).toBe(true);
|
expect(component.hasFloatingToc).toBe(true);
|
||||||
@ -127,37 +125,47 @@ describe('AppComponent', () => {
|
|||||||
it('should be false when toc is empty', () => {
|
it('should be false when toc is empty', () => {
|
||||||
tocService.tocList.next([]);
|
tocService.tocList.next([]);
|
||||||
|
|
||||||
component.onResize(hideToCBreakPoint + 1);
|
component.onResize(showFloatingTocWidth + 1);
|
||||||
expect(component.hasFloatingToc).toBe(false);
|
expect(component.hasFloatingToc).toBe(false);
|
||||||
|
|
||||||
component.onResize(hideToCBreakPoint - 1);
|
component.onResize(showFloatingTocWidth - 1);
|
||||||
expect(component.hasFloatingToc).toBe(false);
|
expect(component.hasFloatingToc).toBe(false);
|
||||||
|
|
||||||
component.onResize(hideToCBreakPoint + 1);
|
component.onResize(showFloatingTocWidth + 1);
|
||||||
expect(component.hasFloatingToc).toBe(false);
|
expect(component.hasFloatingToc).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be true when toc is not empty unless the screen is narrow', () => {
|
it('should be true when toc is not empty unless the screen is narrow', () => {
|
||||||
tocService.tocList.next([{}, {}, {}] as TocItem[]);
|
tocService.tocList.next([{}, {}, {}] as TocItem[]);
|
||||||
|
|
||||||
component.onResize(hideToCBreakPoint + 1);
|
component.onResize(showFloatingTocWidth + 1);
|
||||||
expect(component.hasFloatingToc).toBe(true);
|
expect(component.hasFloatingToc).toBe(true);
|
||||||
|
|
||||||
component.onResize(hideToCBreakPoint - 1);
|
component.onResize(showFloatingTocWidth - 1);
|
||||||
expect(component.hasFloatingToc).toBe(false);
|
expect(component.hasFloatingToc).toBe(false);
|
||||||
|
|
||||||
component.onResize(hideToCBreakPoint + 1);
|
component.onResize(showFloatingTocWidth + 1);
|
||||||
expect(component.hasFloatingToc).toBe(true);
|
expect(component.hasFloatingToc).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('isSideBySide', () => {
|
describe('showTopMenu', () => {
|
||||||
it('should be updated on resize', () => {
|
it('should be updated on resize', () => {
|
||||||
component.onResize(sideBySideBreakPoint - 1);
|
component.onResize(showTopMenuWidth - 1);
|
||||||
expect(component.isSideBySide).toBe(false);
|
expect(component.showTopMenu).toBe(false);
|
||||||
|
|
||||||
component.onResize(sideBySideBreakPoint + 1);
|
component.onResize(showTopMenuWidth + 1);
|
||||||
expect(component.isSideBySide).toBe(true);
|
expect(component.showTopMenu).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('dockSideNav', () => {
|
||||||
|
it('should be updated on resize', () => {
|
||||||
|
component.onResize(dockSideNavWidth - 1);
|
||||||
|
expect(component.dockSideNav).toBe(false);
|
||||||
|
|
||||||
|
component.onResize(dockSideNavWidth + 1);
|
||||||
|
expect(component.dockSideNav).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -185,8 +193,8 @@ describe('AppComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('when side-by-side (wide)', () => {
|
describe('when view is wide', () => {
|
||||||
beforeEach(() => resizeTo(sideBySideBreakPoint + 1)); // side-by-side
|
beforeEach(() => resizeTo(dockSideNavWidth + 1)); // wide view
|
||||||
|
|
||||||
it('should open when navigating to a guide page (guide/pipes)', () => {
|
it('should open when navigating to a guide page (guide/pipes)', () => {
|
||||||
navigateTo('guide/pipes');
|
navigateTo('guide/pipes');
|
||||||
@ -232,8 +240,8 @@ describe('AppComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when NOT side-by-side (narrow)', () => {
|
describe('when view is narrow', () => {
|
||||||
beforeEach(() => resizeTo(sideBySideBreakPoint - 1)); // NOT side-by-side
|
beforeEach(() => resizeTo(dockSideNavWidth - 1)); // narrow view
|
||||||
|
|
||||||
it('should be closed when navigating to a guide page (guide/pipes)', () => {
|
it('should be closed when navigating to a guide page (guide/pipes)', () => {
|
||||||
navigateTo('guide/pipes');
|
navigateTo('guide/pipes');
|
||||||
@ -286,30 +294,30 @@ describe('AppComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when changing side-by-side (narrow --> wide)', () => {
|
describe('when changing from narrow to wide view', () => {
|
||||||
const sidenavDocs = ['api/a/b/c/d', 'guide/pipes'];
|
const sidenavDocs = ['api/a/b/c/d', 'guide/pipes'];
|
||||||
const nonSidenavDocs = ['features', 'about'];
|
const nonSidenavDocs = ['features', 'about'];
|
||||||
|
|
||||||
sidenavDocs.forEach(doc => {
|
sidenavDocs.forEach(doc => {
|
||||||
it(`should open when on a sidenav doc (${doc})`, () => {
|
it(`should open when on a sidenav doc (${doc})`, () => {
|
||||||
resizeTo(sideBySideBreakPoint - 1);
|
resizeTo(dockSideNavWidth - 1);
|
||||||
|
|
||||||
navigateTo(doc);
|
navigateTo(doc);
|
||||||
expect(sidenav.opened).toBe(false);
|
expect(sidenav.opened).toBe(false);
|
||||||
|
|
||||||
resizeTo(sideBySideBreakPoint + 1);
|
resizeTo(dockSideNavWidth + 1);
|
||||||
expect(sidenav.opened).toBe(true);
|
expect(sidenav.opened).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
nonSidenavDocs.forEach(doc => {
|
nonSidenavDocs.forEach(doc => {
|
||||||
it(`should remain closed when on a non-sidenav doc (${doc})`, () => {
|
it(`should remain closed when on a non-sidenav doc (${doc})`, () => {
|
||||||
resizeTo(sideBySideBreakPoint - 1);
|
resizeTo(dockSideNavWidth - 1);
|
||||||
|
|
||||||
navigateTo(doc);
|
navigateTo(doc);
|
||||||
expect(sidenav.opened).toBe(false);
|
expect(sidenav.opened).toBe(false);
|
||||||
|
|
||||||
resizeTo(sideBySideBreakPoint + 1);
|
resizeTo(dockSideNavWidth + 1);
|
||||||
expect(sidenav.opened).toBe(false);
|
expect(sidenav.opened).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -317,33 +325,33 @@ describe('AppComponent', () => {
|
|||||||
describe('when manually opened', () => {
|
describe('when manually opened', () => {
|
||||||
sidenavDocs.forEach(doc => {
|
sidenavDocs.forEach(doc => {
|
||||||
it(`should remain opened when on a sidenav doc (${doc})`, () => {
|
it(`should remain opened when on a sidenav doc (${doc})`, () => {
|
||||||
resizeTo(sideBySideBreakPoint - 1);
|
resizeTo(dockSideNavWidth - 1);
|
||||||
|
|
||||||
navigateTo(doc);
|
navigateTo(doc);
|
||||||
toggleSidenav();
|
toggleSidenav();
|
||||||
expect(sidenav.opened).toBe(true);
|
expect(sidenav.opened).toBe(true);
|
||||||
|
|
||||||
resizeTo(sideBySideBreakPoint + 1);
|
resizeTo(dockSideNavWidth + 1);
|
||||||
expect(sidenav.opened).toBe(true);
|
expect(sidenav.opened).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
nonSidenavDocs.forEach(doc => {
|
nonSidenavDocs.forEach(doc => {
|
||||||
it(`should close when on a non-sidenav doc (${doc})`, () => {
|
it(`should close when on a non-sidenav doc (${doc})`, () => {
|
||||||
resizeTo(sideBySideBreakPoint - 1);
|
resizeTo(dockSideNavWidth - 1);
|
||||||
|
|
||||||
navigateTo(doc);
|
navigateTo(doc);
|
||||||
toggleSidenav();
|
toggleSidenav();
|
||||||
expect(sidenav.opened).toBe(true);
|
expect(sidenav.opened).toBe(true);
|
||||||
|
|
||||||
resizeTo(sideBySideBreakPoint + 1);
|
resizeTo(showTopMenuWidth + 1);
|
||||||
expect(sidenav.opened).toBe(false);
|
expect(sidenav.opened).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when changing side-by-side (wide --> narrow)', () => {
|
describe('when changing from wide to narrow view', () => {
|
||||||
const sidenavDocs = ['api/a/b/c/d', 'guide/pipes'];
|
const sidenavDocs = ['api/a/b/c/d', 'guide/pipes'];
|
||||||
const nonSidenavDocs = ['features', 'about'];
|
const nonSidenavDocs = ['features', 'about'];
|
||||||
|
|
||||||
@ -352,7 +360,7 @@ describe('AppComponent', () => {
|
|||||||
navigateTo(doc);
|
navigateTo(doc);
|
||||||
expect(sidenav.opened).toBe(true);
|
expect(sidenav.opened).toBe(true);
|
||||||
|
|
||||||
resizeTo(sideBySideBreakPoint - 1);
|
resizeTo(dockSideNavWidth - 1);
|
||||||
expect(sidenav.opened).toBe(false);
|
expect(sidenav.opened).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -362,7 +370,7 @@ describe('AppComponent', () => {
|
|||||||
navigateTo(doc);
|
navigateTo(doc);
|
||||||
expect(sidenav.opened).toBe(false);
|
expect(sidenav.opened).toBe(false);
|
||||||
|
|
||||||
resizeTo(sideBySideBreakPoint - 1);
|
resizeTo(dockSideNavWidth - 1);
|
||||||
expect(sidenav.opened).toBe(false);
|
expect(sidenav.opened).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -376,7 +384,7 @@ describe('AppComponent', () => {
|
|||||||
async function setupSelectorForTesting(mode?: string) {
|
async function setupSelectorForTesting(mode?: string) {
|
||||||
createTestingModule('a/b', mode);
|
createTestingModule('a/b', mode);
|
||||||
await initializeTest();
|
await initializeTest();
|
||||||
component.onResize(sideBySideBreakPoint + 1); // side-by-side
|
component.onResize(dockSideNavWidth + 1); // wide view
|
||||||
selectElement = fixture.debugElement.query(By.directive(SelectComponent));
|
selectElement = fixture.debugElement.query(By.directive(SelectComponent));
|
||||||
selectComponent = selectElement.componentInstance;
|
selectComponent = selectElement.componentInstance;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,9 @@ import { BehaviorSubject, combineLatest, Observable } from 'rxjs';
|
|||||||
import { first, map } from 'rxjs/operators';
|
import { first, map } from 'rxjs/operators';
|
||||||
|
|
||||||
const sideNavView = 'SideNav';
|
const sideNavView = 'SideNav';
|
||||||
|
export const showTopMenuWidth = 1048;
|
||||||
|
export const dockSideNavWidth = 992;
|
||||||
|
export const showFloatingTocWidth = 800;
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'aio-shell',
|
selector: 'aio-shell',
|
||||||
@ -57,18 +60,17 @@ export class AppComponent implements OnInit {
|
|||||||
isStarting = true;
|
isStarting = true;
|
||||||
isTransitioning = true;
|
isTransitioning = true;
|
||||||
isFetching = false;
|
isFetching = false;
|
||||||
isSideBySide = false;
|
showTopMenu = false;
|
||||||
|
dockSideNav = false;
|
||||||
private isFetchingTimeout: any;
|
private isFetchingTimeout: any;
|
||||||
private isSideNavDoc = false;
|
private isSideNavDoc = false;
|
||||||
|
|
||||||
private sideBySideWidth = 992;
|
|
||||||
sideNavNodes: NavigationNode[];
|
sideNavNodes: NavigationNode[];
|
||||||
topMenuNodes: NavigationNode[];
|
topMenuNodes: NavigationNode[];
|
||||||
topMenuNarrowNodes: NavigationNode[];
|
topMenuNarrowNodes: NavigationNode[];
|
||||||
|
|
||||||
hasFloatingToc = false;
|
hasFloatingToc = false;
|
||||||
private showFloatingToc = new BehaviorSubject(false);
|
private showFloatingToc = new BehaviorSubject(false);
|
||||||
private showFloatingTocWidth = 800;
|
|
||||||
tocMaxHeight: string;
|
tocMaxHeight: string;
|
||||||
private tocMaxHeightOffset = 0;
|
private tocMaxHeightOffset = 0;
|
||||||
|
|
||||||
@ -76,8 +78,8 @@ export class AppComponent implements OnInit {
|
|||||||
|
|
||||||
private currentUrl: string;
|
private currentUrl: string;
|
||||||
|
|
||||||
get isOpened() { return this.isSideBySide && this.isSideNavDoc; }
|
get isOpened() { return this.dockSideNav && this.isSideNavDoc; }
|
||||||
get mode() { return this.isSideBySide ? 'side' : 'over'; }
|
get mode() { return this.dockSideNav && (this.isSideNavDoc || this.showTopMenu) ? 'side' : 'over'; }
|
||||||
|
|
||||||
// Search related properties
|
// Search related properties
|
||||||
showSearchResults = false;
|
showSearchResults = false;
|
||||||
@ -239,13 +241,14 @@ export class AppComponent implements OnInit {
|
|||||||
|
|
||||||
@HostListener('window:resize', ['$event.target.innerWidth'])
|
@HostListener('window:resize', ['$event.target.innerWidth'])
|
||||||
onResize(width: number) {
|
onResize(width: number) {
|
||||||
this.isSideBySide = width >= this.sideBySideWidth;
|
this.showTopMenu = width >= showTopMenuWidth;
|
||||||
this.showFloatingToc.next(width > this.showFloatingTocWidth);
|
this.dockSideNav = width >= dockSideNavWidth;
|
||||||
|
this.showFloatingToc.next(width > showFloatingTocWidth);
|
||||||
|
|
||||||
if (this.isSideBySide && !this.isSideNavDoc) {
|
if (this.showTopMenu && !this.isSideNavDoc) {
|
||||||
// If this is a non-sidenav doc and the screen is wide enough so that we can display menu
|
// If this is a non-sidenav doc and the screen is wide enough so that we can display menu
|
||||||
// items in the top-bar, ensure the sidenav is closed.
|
// items in the top-bar, ensure the sidenav is closed.
|
||||||
// (This condition can only be met when the resize event changes the value of `isSideBySide`
|
// (This condition can only be met when the resize event changes the value of `showTopMenu`
|
||||||
// from `false` to `true` while on a non-sidenav doc.)
|
// from `false` to `true` while on a non-sidenav doc.)
|
||||||
this.sidenav.toggle(false);
|
this.sidenav.toggle(false);
|
||||||
}
|
}
|
||||||
@ -338,7 +341,7 @@ export class AppComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// May be open or closed when wide; always closed when narrow.
|
// May be open or closed when wide; always closed when narrow.
|
||||||
this.sidenav.toggle(this.isSideBySide && openSideNav);
|
this.sidenav.toggle(this.dockSideNav && openSideNav);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dynamically change height of table of contents container
|
// Dynamically change height of table of contents container
|
||||||
|
@ -1,27 +1,31 @@
|
|||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { ErrorHandler } from '@angular/core';
|
||||||
import { MatIconRegistry } from '@angular/material/icon';
|
import { MatIconRegistry } from '@angular/material/icon';
|
||||||
|
import { DomSanitizer } from '@angular/platform-browser';
|
||||||
import { CustomIconRegistry, SvgIconInfo } from './custom-icon-registry';
|
import { CustomIconRegistry, SvgIconInfo } from './custom-icon-registry';
|
||||||
|
|
||||||
describe('CustomIconRegistry', () => {
|
describe('CustomIconRegistry', () => {
|
||||||
|
const fakeHttpClient: HttpClient = {} as any;
|
||||||
|
const fakeDomSanitizer: DomSanitizer = {} as any;
|
||||||
|
const fakeDocument: Document = {} as any;
|
||||||
|
const fakeErrorHandler: ErrorHandler = {handleError: err => console.error(err)};
|
||||||
|
|
||||||
it('should get the SVG element for a preloaded icon from the cache', () => {
|
it('should get the SVG element for a preloaded icon from the cache', () => {
|
||||||
const mockHttp: any = {};
|
|
||||||
const mockSanitizer: any = {};
|
|
||||||
const mockDocument: any = {};
|
|
||||||
const svgSrc = '<svg xmlns="http://www.w3.org/2000/svg" focusable="false" ' +
|
const svgSrc = '<svg xmlns="http://www.w3.org/2000/svg" focusable="false" ' +
|
||||||
'viewBox="0 0 24 24"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"/></svg>';
|
'viewBox="0 0 24 24"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"/></svg>';
|
||||||
const svgIcons: SvgIconInfo[] = [
|
const svgIcons: SvgIconInfo[] = [
|
||||||
{ name: 'test_icon', svgSource: svgSrc }
|
{ name: 'test_icon', svgSource: svgSrc }
|
||||||
];
|
];
|
||||||
const registry = new CustomIconRegistry(mockHttp, mockSanitizer, mockDocument, svgIcons);
|
|
||||||
|
const registry = new CustomIconRegistry(
|
||||||
|
fakeHttpClient, fakeDomSanitizer, fakeDocument, fakeErrorHandler, svgIcons);
|
||||||
let svgElement: SVGElement|undefined;
|
let svgElement: SVGElement|undefined;
|
||||||
registry.getNamedSvgIcon('test_icon').subscribe(el => svgElement = el);
|
registry.getNamedSvgIcon('test_icon').subscribe(el => svgElement = el);
|
||||||
|
|
||||||
expect(svgElement).toEqual(createSvg(svgSrc));
|
expect(svgElement).toEqual(createSvg(svgSrc));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support caching icons with a namespace', () => {
|
it('should support caching icons with a namespace', () => {
|
||||||
const mockHttp: any = {};
|
|
||||||
const mockSanitizer: any = {};
|
|
||||||
const mockDocument: any = {};
|
|
||||||
|
|
||||||
const svgSrc1 = '<svg xmlns="http://www.w3.org/2000/svg"><path d="h100" /></svg>';
|
const svgSrc1 = '<svg xmlns="http://www.w3.org/2000/svg"><path d="h100" /></svg>';
|
||||||
const svgSrc2 = '<svg xmlns="http://www.w3.org/2000/svg"><path d="h200" /></svg>';
|
const svgSrc2 = '<svg xmlns="http://www.w3.org/2000/svg"><path d="h200" /></svg>';
|
||||||
const svgSrc3 = '<svg xmlns="http://www.w3.org/2000/svg"><path d="h300" /></svg>';
|
const svgSrc3 = '<svg xmlns="http://www.w3.org/2000/svg"><path d="h300" /></svg>';
|
||||||
@ -31,7 +35,8 @@ describe('CustomIconRegistry', () => {
|
|||||||
{ namespace: 'bar', name: 'test_icon', svgSource: svgSrc3 },
|
{ namespace: 'bar', name: 'test_icon', svgSource: svgSrc3 },
|
||||||
];
|
];
|
||||||
|
|
||||||
const registry = new CustomIconRegistry(mockHttp, mockSanitizer, mockDocument, svgIcons);
|
const registry = new CustomIconRegistry(
|
||||||
|
fakeHttpClient, fakeDomSanitizer, fakeDocument, fakeErrorHandler, svgIcons);
|
||||||
let svgElement: SVGElement|undefined;
|
let svgElement: SVGElement|undefined;
|
||||||
registry.getNamedSvgIcon('test_icon', 'foo').subscribe(el => svgElement = el);
|
registry.getNamedSvgIcon('test_icon', 'foo').subscribe(el => svgElement = el);
|
||||||
|
|
||||||
@ -39,9 +44,6 @@ describe('CustomIconRegistry', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should call through to the MdIconRegistry if the icon name is not in the preloaded cache', () => {
|
it('should call through to the MdIconRegistry if the icon name is not in the preloaded cache', () => {
|
||||||
const mockHttp: any = {};
|
|
||||||
const mockSanitizer: any = {};
|
|
||||||
const mockDocument: any = {};
|
|
||||||
const svgSrc = '<svg xmlns="http://www.w3.org/2000/svg" focusable="false" ' +
|
const svgSrc = '<svg xmlns="http://www.w3.org/2000/svg" focusable="false" ' +
|
||||||
'viewBox="0 0 24 24"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"/></svg>';
|
'viewBox="0 0 24 24"><path d="M8.59 16.34l4.58-4.59-4.58-4.59L10 5.75l6 6-6 6z"/></svg>';
|
||||||
const svgIcons: SvgIconInfo[] = [
|
const svgIcons: SvgIconInfo[] = [
|
||||||
@ -49,7 +51,8 @@ describe('CustomIconRegistry', () => {
|
|||||||
];
|
];
|
||||||
spyOn(MatIconRegistry.prototype, 'getNamedSvgIcon');
|
spyOn(MatIconRegistry.prototype, 'getNamedSvgIcon');
|
||||||
|
|
||||||
const registry = new CustomIconRegistry(mockHttp, mockSanitizer, mockDocument, svgIcons);
|
const registry = new CustomIconRegistry(
|
||||||
|
fakeHttpClient, fakeDomSanitizer, fakeDocument, fakeErrorHandler, svgIcons);
|
||||||
|
|
||||||
registry.getNamedSvgIcon('other_icon');
|
registry.getNamedSvgIcon('other_icon');
|
||||||
expect(MatIconRegistry.prototype.getNamedSvgIcon).toHaveBeenCalledWith('other_icon', undefined);
|
expect(MatIconRegistry.prototype.getNamedSvgIcon).toHaveBeenCalledWith('other_icon', undefined);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { InjectionToken, Inject, Injectable, Optional } from '@angular/core';
|
import { ErrorHandler, InjectionToken, Inject, Injectable, Optional } from '@angular/core';
|
||||||
import { DOCUMENT } from '@angular/common';
|
import { DOCUMENT } from '@angular/common';
|
||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { MatIconRegistry } from '@angular/material/icon';
|
import { MatIconRegistry } from '@angular/material/icon';
|
||||||
@ -42,8 +42,8 @@ export class CustomIconRegistry extends MatIconRegistry {
|
|||||||
private preloadedSvgElements: SvgIconMap = {[DEFAULT_NS]: {}};
|
private preloadedSvgElements: SvgIconMap = {[DEFAULT_NS]: {}};
|
||||||
|
|
||||||
constructor(http: HttpClient, sanitizer: DomSanitizer, @Optional() @Inject(DOCUMENT) document: Document,
|
constructor(http: HttpClient, sanitizer: DomSanitizer, @Optional() @Inject(DOCUMENT) document: Document,
|
||||||
@Inject(SVG_ICONS) svgIcons: SvgIconInfo[]) {
|
errorHandler: ErrorHandler, @Inject(SVG_ICONS) svgIcons: SvgIconInfo[]) {
|
||||||
super(http, sanitizer, document);
|
super(http, sanitizer, document, errorHandler);
|
||||||
this.loadSvgElements(svgIcons);
|
this.loadSvgElements(svgIcons);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
/* You can add global styles to this file, and also import other style files */
|
|
||||||
@import './styles/ng-io-theme';
|
|
||||||
@import './styles/main.scss';
|
|
@ -193,6 +193,11 @@ code {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The following css rule adds an icon to external links in the docs area.
|
||||||
|
// The following `folder-*` classes are applied to the `doc-viewer`component when it is displaying docs for these areas of the documentation.
|
||||||
|
// We add the icon to all external links which are identified as absolute links (those that start with `http` or https`).
|
||||||
|
// For more info see PR #36601
|
||||||
|
|
||||||
.folder-api,
|
.folder-api,
|
||||||
.folder-cli,
|
.folder-cli,
|
||||||
.folder-docs,
|
.folder-docs,
|
||||||
@ -213,6 +218,8 @@ code {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The docs-viewer also contain links to GitHub (e.g. the edit this page icon) identified with `.github-links` class.
|
||||||
|
// We don't want to add the external link icon to these links, so we hide them.
|
||||||
.github-links a {
|
.github-links a {
|
||||||
&[href^="http:"]::after,
|
&[href^="http:"]::after,
|
||||||
&[href^="https:"]::after {
|
&[href^="https:"]::after {
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
// VARIABLES
|
// VARIABLES
|
||||||
|
$showTopMenuWidth: 1048px;
|
||||||
|
$hideTopMenuWidth: $showTopMenuWidth - 1;
|
||||||
$hamburgerShownMargin: 0 8px 0 0;
|
$hamburgerShownMargin: 0 8px 0 0;
|
||||||
$hamburgerHiddenMargin: 0 16px 0 -64px;
|
$hamburgerHiddenMargin: 0 16px 0 -64px;
|
||||||
|
|
||||||
@ -59,9 +61,9 @@ aio-shell.folder-docs mat-toolbar.mat-toolbar,
|
|||||||
aio-shell.folder-guide mat-toolbar.mat-toolbar,
|
aio-shell.folder-guide mat-toolbar.mat-toolbar,
|
||||||
aio-shell.folder-start mat-toolbar.mat-toolbar,
|
aio-shell.folder-start mat-toolbar.mat-toolbar,
|
||||||
aio-shell.folder-tutorial mat-toolbar.mat-toolbar {
|
aio-shell.folder-tutorial mat-toolbar.mat-toolbar {
|
||||||
@media (min-width: 992px) {
|
@media (min-width: $showTopMenuWidth) {
|
||||||
.hamburger.mat-button {
|
.hamburger.mat-button {
|
||||||
// Hamburger shown on non-marketing pages on large screens.
|
// Hamburger shown on non-marketing pages even on large screens.
|
||||||
margin: $hamburgerShownMargin;
|
margin: $hamburgerShownMargin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,7 +75,7 @@ aio-shell.folder-tutorial mat-toolbar.mat-toolbar {
|
|||||||
margin: $hamburgerShownMargin;
|
margin: $hamburgerShownMargin;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
||||||
@media (min-width: 992px) {
|
@media (min-width: $showTopMenuWidth) {
|
||||||
// Hamburger hidden by default on large screens.
|
// Hamburger hidden by default on large screens.
|
||||||
// (Will be shown per doc.)
|
// (Will be shown per doc.)
|
||||||
margin: $hamburgerHiddenMargin;
|
margin: $hamburgerHiddenMargin;
|
||||||
@ -111,7 +113,7 @@ aio-shell.folder-tutorial mat-toolbar.mat-toolbar {
|
|||||||
outline-offset: 4px;
|
outline-offset: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 991px) {
|
@media screen and (max-width: $hideTopMenuWidth) {
|
||||||
padding: 4px 0;
|
padding: 4px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +127,7 @@ aio-shell.folder-tutorial mat-toolbar.mat-toolbar {
|
|||||||
top: 12px;
|
top: 12px;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
|
|
||||||
@media (max-width: 991px) {
|
@media (max-width: $hideTopMenuWidth) {
|
||||||
&:hover {
|
&:hover {
|
||||||
transform: scale(1.1);
|
transform: scale(1.1);
|
||||||
}
|
}
|
||||||
@ -237,6 +239,7 @@ aio-search-box.search-container {
|
|||||||
width: 80%;
|
width: 80%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 480px) {
|
@media (max-width: 480px) {
|
||||||
width: 150px;
|
width: 150px;
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user