mirror of
https://github.com/angular/angular.git
synced 2026-11-23 07:05:14 -05:00
docs: clarify boundary content projection limitation
(cherry picked from commit 1a32087b4d)
This commit is contained in:
committed by
Jessica Janiuk
parent
bc402cf407
commit
20fa87dc24
@@ -18,6 +18,32 @@ The `@boundary` block wraps a section of your template. If any component or dire
|
||||
}
|
||||
```
|
||||
|
||||
## Content projection
|
||||
|
||||
If your component uses [content projection](guide/components/content-projection), wrapping `<ng-content>` in a `@boundary` does not catch errors from projected content. That content belongs to the view that declares it, not the receiving component's view.
|
||||
|
||||
For example, a wrapper component with the following template does not catch errors from components projected into it:
|
||||
|
||||
```angular-html
|
||||
@boundary {
|
||||
<ng-content />
|
||||
} @error {
|
||||
<p>Something went wrong!</p>
|
||||
}
|
||||
```
|
||||
|
||||
To catch those errors, wrap the wrapper component and its projected content in a `@boundary` in the parent template:
|
||||
|
||||
```angular-html
|
||||
@boundary {
|
||||
<app-wrapper>
|
||||
<app-risky-component />
|
||||
</app-wrapper>
|
||||
} @error {
|
||||
<p>Something went wrong!</p>
|
||||
}
|
||||
```
|
||||
|
||||
## Accessing the error object
|
||||
|
||||
You can access the caught error by accessing the implicit `$error` variable:
|
||||
|
||||
@@ -16,6 +16,8 @@ The `@boundary` block is a control flow mechanism that lets you intercept and ha
|
||||
|
||||
The `@boundary` block encapsulates its content and catches any errors that occur during the initial render or subsequent change detection cycles of its child views. If an error is caught, the framework stops rendering the main view and instead renders the fallback UI provided in the `@error` block.
|
||||
|
||||
IMPORTANT: Wrapping `<ng-content>` in a `@boundary` does not catch errors from projected content. See [Content projection with error boundaries](guide/templates/error-boundaries#content-projection).
|
||||
|
||||
You can capture the error object by declaring a variable in the `@error` block, for example `@error (let err)`.
|
||||
|
||||
You can use multiple `@error` blocks with `when` clauses to conditionally render different fallbacks based on the error type, with a final fallback `@error` block at the end. You can also access a `$reset` function to attempt re-rendering the boundary content.
|
||||
|
||||
Reference in New Issue
Block a user