Skip to content

Commit f941ea6

Browse files
fix(angular-table): handle null and number values with flex-render (#5550)
* fix: handle flex-render null * fix: handle flex-render null * support number values in flex-render
1 parent d064a6f commit f941ea6

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

packages/angular-table/src/flex-render.ts

+19-8
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import {
1616

1717
type FlexRenderContent<TProps extends NonNullable<unknown>> =
1818
| string
19+
| number
1920
| FlexRenderComponent<TProps>
2021
| TemplateRef<{ $implicit: TProps }>
22+
| null
2123

2224
@Directive({
2325
selector: '[flexRender]',
@@ -27,8 +29,11 @@ export class FlexRenderDirective<TProps extends NonNullable<unknown>>
2729
implements OnInit, DoCheck
2830
{
2931
@Input({ required: true, alias: 'flexRender' })
30-
content: string | ((props: TProps) => FlexRenderContent<TProps>) | undefined =
31-
undefined
32+
content:
33+
| number
34+
| string
35+
| ((props: TProps) => FlexRenderContent<TProps>)
36+
| undefined = undefined
3237

3338
@Input({ required: true, alias: 'flexRenderProps' })
3439
props: TProps = {} as TProps
@@ -62,7 +67,7 @@ export class FlexRenderDirective<TProps extends NonNullable<unknown>>
6267
return null
6368
}
6469

65-
if (typeof content === 'string') {
70+
if (typeof content === 'string' || typeof content === 'number') {
6671
return this.renderStringContent()
6772
}
6873
if (typeof content === 'function') {
@@ -72,21 +77,25 @@ export class FlexRenderDirective<TProps extends NonNullable<unknown>>
7277
}
7378

7479
private renderContent(content: FlexRenderContent<TProps>) {
75-
if (typeof content === 'string') {
80+
if (typeof content === 'string' || typeof content === 'number') {
7681
return this.renderStringContent()
7782
}
7883
if (content instanceof TemplateRef) {
7984
return this.viewContainerRef.createEmbeddedView(
8085
content,
8186
this.getTemplateRefContext()
8287
)
88+
} else if (content instanceof FlexRenderComponent) {
89+
return this.renderComponent(content)
90+
} else {
91+
return null
8392
}
84-
return this.renderComponent(content)
8593
}
8694

87-
private renderStringContent() {
95+
private renderStringContent(): EmbeddedViewRef<unknown> {
8896
const context = () => {
89-
return typeof this.content === 'string'
97+
return typeof this.content === 'string' ||
98+
typeof this.content === 'number'
9099
? this.content
91100
: this.content?.(this.props)
92101
}
@@ -97,7 +106,9 @@ export class FlexRenderDirective<TProps extends NonNullable<unknown>>
97106
})
98107
}
99108

100-
private renderComponent(flexRenderComponent: FlexRenderComponent<TProps>) {
109+
private renderComponent(
110+
flexRenderComponent: FlexRenderComponent<TProps>
111+
): ComponentRef<unknown> {
101112
const { component, inputs, injector } = flexRenderComponent
102113

103114
const getContext = () => this.props

0 commit comments

Comments
 (0)