You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(compiler): support passing @content blocks as functions
Previously, foreign component `@content` blocks were rendered eagerly by
Angular and could only project a list of nodes. With this change, `@content`
can be used to declare a function (e.g. `@content(renderItem; let item)`) that
is passed as a callback prop to the foreign component, allowing the foreign
component to invoke it with context arguments at its leisure.
Implementation details:
- Introduces a new runtime instruction `ɵɵforeignContentFn` which wraps the
template function so it can be called on demand with arguments by the foreign
component.
- Extends the compiler AST to parse and validate `@content` parameters.
- Maps `@content` parameters to the corresponding positional arguments of the
calling foreign component function property.
Copy file name to clipboardExpand all lines: packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/standalone/GOLDEN_PARTIAL.js
Copy file name to clipboardExpand all lines: packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/standalone/foreign_component.js
+34Lines changed: 34 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,20 @@ function TestCmpChildren_Children_2_Template(rf, ctx) {
Copy file name to clipboardExpand all lines: packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/standalone/foreign_component.local.js
+33Lines changed: 33 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,20 @@ function TestCmpChildren_Children_2_Template(rf, ctx) {
Copy file name to clipboardExpand all lines: packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/standalone/foreign_component.ts
+19Lines changed: 19 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -50,3 +50,22 @@ export class TestCmpChildren {
50
50
title='Submit';
51
51
}
52
52
53
+
@Component({
54
+
selector: 'main-render-props',
55
+
template: `
56
+
<FancyButton [label]="title">
57
+
@content(items; let item, index) {
58
+
<span>#{{index}}: {{item}}</span>
59
+
}
60
+
</FancyButton>
61
+
`,
62
+
// @ts-ignore: @angular/core does not expose the `foreignImports` property.
63
+
foreignImports: [
64
+
// @ts-ignore: @angular/core does not expose the `ForeignComponent` type this expects.
0 commit comments