Skip to content

Commit

Permalink
docs: improve markdown (#45590)
Browse files Browse the repository at this point in the history
improve markdown for documentation. Duplicate of #45325 that targets 13.3.x.

PR Close #45590
  • Loading branch information
josmar-crwdstffng authored and thePunderWoman committed Apr 11, 2022
1 parent 09c5c18 commit 6189457
Show file tree
Hide file tree
Showing 250 changed files with 19,089 additions and 24,001 deletions.
49 changes: 33 additions & 16 deletions aio/content/cli/cache.md
@@ -1,15 +1,17 @@

# Persistent disk cache

Angular CLI saves a number of cachable operations on disk by default.

When you re-run the same build, the build system restores the state of the previous build and re-uses previously performed operations, which decreases the time taken to build and test your applications and libraries.

To amend the default cache settings, add the `cli.cache` object to your [Workspace Configuration](guide/workspace-config).
The object goes under `cli.cache` at the top level of the file, outside the `projects` sections.

```json
<code-example format="json" language="json">

{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"$schema": "./node_modules/&commat;angular/cli/lib/config/schema.json",
"version": 1,
"cli": {
"cache": {
Expand All @@ -18,27 +20,35 @@ The object goes under `cli.cache` at the top level of the file, outside the `pro
},
"projects": {}
}
```

</code-example>

For more information, see [cache options](guide/workspace-config#cache-options).

### Enabling and disabling the cache
Caching is enabled by default. To disable caching run the following command:

```bash
Caching is enabled by default.
To disable caching run the following command:

<code-example format="shell" language="shell">

ng config cli.cache.enabled false
```

</code-example>

To re-enable caching, set `cli.cache.enabled` to `true`.

### Cache environments

By default, disk cache is only enabled for local environments.

To enable caching for all environments, run the following command:

```bash
<code-example format="shell" language="shell">

ng config cli.cache.environment all
```

</code-example>

For more information, see `environment` in [cache options](guide/workspace-config#cache-options).

Expand All @@ -50,26 +60,33 @@ The Angular CLI checks for the presence and value of the `CI` environment variab

### Cache path

By default, `.angular/cache` is used as a base directory to store cache results. To change this path, run the following command:
By default, `.angular/cache` is used as a base directory to store cache results.
To change this path, run the following command:

<code-example format="shell" language="shell">

```bash
ng config cli.cache.path ".cache/ng"
```

</code-example>

### Clearing the cache

To clear the cache, run one of the following commands.

To clear the cache on Unix-based operating systems:

```bash
<code-example format="shell" language="shell">

rm -rf .angular/cache
```

</code-example>

To clear the cache on Windows:

```bash
<code-example format="shell" language="shell">

rmdir /s /q .angular\cache
```

For more information, see [rm command](https://man7.org/linux/man-pages/man1/rm.1.html) and [rmdir command](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/rmdir).
</code-example>

For more information, see [rm command](https://man7.org/linux/man-pages/man1/rm.1.html) and [rmdir command](https://docs.microsoft.com/windows-server/administration/windows-commands/rmdir).
69 changes: 46 additions & 23 deletions aio/content/cli/index.md
Expand Up @@ -7,40 +7,47 @@ The Angular CLI is a command-line interface tool that you use to initialize, dev
Major versions of Angular CLI follow the supported major version of Angular, but minor versions can be released separately.

Install the CLI using the `npm` package manager:
<code-example language="bash">
npm install -g @angular/cli

<code-example format="shell" language="shell">

npm install -g &commat;angular/cli

</code-example>

For details about changes between versions, and information about updating from previous releases,
see the Releases tab on GitHub: https://github.com/angular/angular-cli/releases
For details about changes between versions, and information about updating from previous releases, see the Releases tab on GitHub: https://github.com/angular/angular-cli/releases

## Basic workflow

Invoke the tool on the command line through the `ng` executable.
Online help is available on the command line.
Enter the following to list commands or options for a given command (such as [generate](cli/generate)) with a short description.
Enter the following to list commands or options for a given command \(such as [generate](cli/generate)\) with a short description.

<code-example format="shell" language="shell">

<code-example language="bash">
ng help
ng generate --help

</code-example>

To create, build, and serve a new, basic Angular project on a development server, go to the parent directory of your new workspace use the following commands:

<code-example language="bash">
<code-example format="shell" language="shell">

ng new my-first-project
cd my-first-project
ng serve

</code-example>

In your browser, open http://localhost:4200/ to see the new application run.
When you use the [ng serve](cli/serve) command to build an application and serve it locally, the server automatically rebuilds the application and reloads the page when you change any of the source files.

<div class="alert is-helpful">

When you run `ng new my-first-project` a new folder, named `my-first-project`, will be created in the current working directory. Since you want to be able to create files inside that folder, make sure you have sufficient rights in the current working directory before running the command.
When you run `ng new my-first-project` a new folder, named `my-first-project`, will be created in the current working directory.
Since you want to be able to create files inside that folder, make sure you have sufficient rights in the current working directory before running the command.

If the current working directory is not the right place for your project, you can change to a more appropriate directory by running `cd <path-to-other-directory>` first.
If the current working directory is not the right place for your project, you can change to a more appropriate directory by running `cd <path-to-other-directory>`.

</div>

Expand All @@ -58,52 +65,68 @@ You can edit the generated files directly, or add to and modify them using CLI c
Use the [ng generate](cli/generate) command to add new files for additional components and services, and code for new pipes, directives, and so on.
Commands such as [add](cli/add) and [generate](cli/generate), which create or operate on applications and libraries, must be executed from within a workspace or project folder.

* See more about the [Workspace file structure](guide/file-structure).
* See more about the [Workspace file structure](guide/file-structure).

### Workspace and project configuration

A single workspace configuration file, `angular.json`, is created at the top level of the workspace.
This is where you can set per-project defaults for CLI command options, and specify configurations to use when the CLI builds a project for different targets.

The [ng config](cli/config) command lets you set and retrieve configuration values from the command line, or you can edit the `angular.json` file directly.
Note that option names in the configuration file must use [camelCase](guide/glossary#case-types), while option names supplied to commands must be dash-case.

* See more about [Workspace Configuration](guide/workspace-config).
<div class="alert is-helpful">

**NOTE**: <br />
Option names in the configuration file must use [camelCase](guide/glossary#case-types), while option names supplied to commands must be dash-case.

</div>

* See more about [Workspace Configuration](guide/workspace-config).

## CLI command-language syntax

Command syntax is shown as follows:

`ng` *commandNameOrAlias* *requiredArg* [*optionalArg*] `[options]`

* Most commands, and some options, have aliases. Aliases are shown in the syntax statement for each command.
* Most commands, and some options, have aliases.
Aliases are shown in the syntax statement for each command.

* Option names are prefixed with a double dash (--).
Option aliases are prefixed with a single dash (-).
* Option names are prefixed with a double dash \(`--`\) characters.
Option aliases are prefixed with a single dash \(`-`\) character.
Arguments are not prefixed.
For example:
<code-example language="bash">
ng build my-app -c production

<code-example format="shell" language="shell">

ng build my-app -c production

</code-example>

* Typically, the name of a generated artifact can be given as an argument to the command or specified with the --name option.
* Typically, the name of a generated artifact can be given as an argument to the command or specified with the `--name` option.

* Argument and option names can be given in either
[camelCase or dash-case](guide/glossary#case-types).
`--myOptionName` is equivalent to `--my-option-name`.
* Argument and option names can be given in either [camelCase or dash-case](guide/glossary#case-types).
`--myOptionName` is equivalent to `--my-option-name`.

### Boolean options

Boolean options have two forms: `--this-option` sets the flag to `true`, `--no-this-option` sets it to `false`.
If neither option is supplied, the flag remains in its default state, as listed in the reference documentation.


### Relative paths

Options that specify files can be given as absolute paths, or as paths relative to the current working directory, which is generally either the workspace or project root.

### Schematics

The [ng generate](cli/generate) and [ng add](cli/add) commands take as an argument the artifact or library to be generated or added to the current project.
The [ng generate](cli/generate) and [ng add](cli/add) commands take, as an argument, the artifact or library to be generated or added to the current project.
In addition to any general options, each artifact or library defines its own options in a *schematic*.
Schematic options are supplied to the command in the same format as immediate command options.

<!-- links -->

<!-- external links -->

<!-- end links -->

@reviewed 2022-02-28
24 changes: 20 additions & 4 deletions aio/content/cli/usage-analytics-gathering.md
Expand Up @@ -20,27 +20,43 @@ This ID is a string that looks like `UA-123456-12`.
You can choose to use a descriptive string as the key value, or be assigned a random key when you run the CLI command.
For example, the following command adds a configuration key named "tracking".

<code-example language="sh">
<code-example format="shell" language="shell">

ng config --global cli.analyticsSharing.tracking UA-123456-12

</code-example>

To turn off this feature, run the following command:

<code-example language="sh">
<code-example format="shell" language="shell">

ng config --global cli.analyticsSharing undefined

</code-example>

## Per user tracking

You can add a custom user ID to the global configuration, in order to identify unique usage of commands and flags.
If that user enables CLI analytics for their own project, your analytics display tracks and labels their individual usage.

<code-example language="sh">
<code-example format="shell" language="shell">

ng config --global cli.analyticsSharing.uuid SOME_USER_NAME

</code-example>

To generate a new random user ID, run the following command:

<code-example language="sh">
<code-example format="shell" language="shell">

ng config --global cli.analyticsSharing.uuid ""

</code-example>

<!-- links -->

<!-- external links -->

<!-- end links -->

@reviewed 2022-02-28
31 changes: 25 additions & 6 deletions aio/content/errors/NG0100.md
Expand Up @@ -4,17 +4,36 @@
@shortDescription Expression has changed after it was checked

@description
Angular throws an `ExpressionChangedAfterItHasBeenCheckedError` when an expression value has been changed after change detection has completed. Angular only throws this error in development mode.

In development mode, Angular performs an additional check after each change detection run, to ensure the bindings haven’t changed. This catches errors where the view is left in an inconsistent state. This can occur, for example, if a method or getter returns a different value each time it is called, or if a child component changes values on its parent. If either of these occur, this is a sign that change detection is not stabilized. Angular throws the error to ensure data is always reflected correctly in the view, which prevents erratic UI behavior or a possible infinite loop.
Angular throws an `ExpressionChangedAfterItHasBeenCheckedError` when an expression value has been changed after change detection has completed.
Angular only throws this error in development mode.

This error commonly occurs when you’ve added template expressions or begun to implement lifecycle hooks like `ngAfterViewInit` or `ngOnChanges`. It is also common when dealing with loading status and asynchronous operations, or a child component changes its parent bindings.
In development mode, Angular performs an additional check after each change detection run, to ensure the bindings haven't changed.
This catches errors where the view is left in an inconsistent state.
This can occur, for example, if a method or getter returns a different value each time it is called, or if a child component changes values on its parent.
If either of these occur, this is a sign that change detection is not stabilized
Angular throws the error to ensure data is always reflected correctly in the view, which prevents erratic UI behavior or a possible infinite loop.

This error commonly occurs when you've added template expressions or have begun to implement lifecycle hooks like `ngAfterViewInit` or `ngOnChanges`.
It is also common when dealing with loading status and asynchronous operations, or when a child component changes its parent bindings.

@debugging
The [source maps](https://developer.mozilla.org/en-US/docs/Tools/Debugger/How_to/Use_a_source_map) generated by the CLI are very useful when debugging. Navigate up the call stack until you find a template expression where the value displayed in the error has changed.

Ensure that there are no changes to the bindings in the template after change detection is run. This often means refactoring to use the correct [component lifecycle hook](guide/lifecycle-hooks) for your use case. If the issue exists within `ngAfterViewInit`, the recommended solution is to use a constructor or `ngOnInit` to set initial values, or use `ngAfterContentInit` for other value bindings.
The [source maps](https://developer.mozilla.org/docs/Tools/Debugger/How_to/Use_a_source_map) generated by the CLI are very useful when debugging.
Navigate up the call stack until you find a template expression where the value displayed in the error has changed.

Ensure that there are no changes to the bindings in the template after change detection is run.
This often means refactoring to use the correct [component lifecycle hook](guide/lifecycle-hooks) for your use case.
If the issue exists within `ngAfterViewInit`, the recommended solution is to use a constructor or `ngOnInit` to set initial values, or use `ngAfterContentInit` for other value bindings.

If you are binding to methods in the view, ensure that the invocation does not update any of the other bindings in the template.

Read more about which solution is right for you in ['Everything you need to know about the "ExpressionChangedAfterItHasBeenCheckedError" error'](https://indepth.dev/posts/1001/everything-you-need-to-know-about-the-expressionchangedafterithasbeencheckederror-error) and why this is useful at ['Angular Debugging "Expression has changed after it was checked": Simple Explanation (and Fix)'](https://blog.angular-university.io/angular-debugging/).
Read more about which solution is right for you in ['Everything you need to know about the "ExpressionChangedAfterItHasBeenCheckedError" error'](https://indepth.dev/posts/1001/everything-you-need-to-know-about-the-expressionchangedafterithasbeencheckederror-error) and why this is useful at ['Angular Debugging "Expression has changed after it was checked": Simple Explanation (and Fix)'](https://blog.angular-university.io/angular-debugging).

<!-- links -->

<!-- external links -->

<!-- end links -->

@reviewed 2022-02-28
20 changes: 17 additions & 3 deletions aio/content/errors/NG0200.md
Expand Up @@ -4,9 +4,23 @@
@shortDescription Circular dependency in DI detected while instantiating a provider

@description
A cyclic dependency exists when a [dependency of a service](guide/hierarchical-dependency-injection) directly or indirectly depends on the service itself. For example, if `UserService` depends on `EmployeeService`, which also depends on `UserService`. Angular will have to instantiate `EmployeeService` to create `UserService`, which depends on `UserService`, itself.

A cyclic dependency exists when a [dependency of a service](guide/hierarchical-dependency-injection) directly or indirectly depends on the service itself.
For example, if `UserService` depends on `EmployeeService`, which also depends on `UserService`.
Angular will have to instantiate `EmployeeService` to create `UserService`, which depends on `UserService`, itself.

@debugging
Use the call stack to determine where the cyclical dependency exists. You will be able to see if any child dependencies rely on the original file by [mapping out](guide/dependency-injection-in-action) the component, module, or service’s dependencies and identify the loop causing the problem.

Break this loop (or circle) of dependency to resolve this error. This most commonly means removing or refactoring the dependencies to not be reliant on one another.
Use the call stack to determine where the cyclical dependency exists.
You will be able to see if any child dependencies rely on the original file by [mapping out](guide/dependency-injection-in-action) the component, module, or service's dependencies, and identifying the loop causing the problem.

Break this loop \(or circle\) of dependency to resolve this error.
This most commonly means removing or refactoring the dependencies to not be reliant on one another.

<!-- links -->

<!-- external links -->

<!-- end links -->

@reviewed 2022-02-28
21 changes: 17 additions & 4 deletions aio/content/errors/NG0201.md
Expand Up @@ -4,17 +4,30 @@
@shortDescription No provider for {token} found!

@description

You see this error when you try to inject a service but have not declared a corresponding provider. A provider is a mapping that supplies a value that you can inject into the constructor of a class in your application.

Read more on providers in our [Dependency Injection guide](guide/dependency-injection).

@debugging
Work backwards from the object where the error states that a [provider](guide/architecture-services) is missing: `No provider for ${this}!`. This is commonly thrown in [services](tutorial/toh-pt4), which require non-existing providers.

Work backwards from the object where the error states that a [provider](guide/architecture-services) is missing: `No provider for ${this}!`.
This is commonly thrown in [services](tutorial/toh-pt4), which require non-existing providers.

To fix the error ensure that your service is registered in the list of providers of an `NgModule` or has the `@Injectable` decorator with a `providedIn` property at top.

The most common solution is to add a provider in `@Injectable` using `providedIn`:

```typescript
@Injectable({ providedIn: 'app' })
```
<code-example format="typescript" language="typescript">

&commat;Injectable({ providedIn: 'app' })

</code-example>

<!-- links -->

<!-- external links -->

<!-- end links -->

@reviewed 2022-02-28

0 comments on commit 6189457

Please sign in to comment.