@@ -16,8 +16,10 @@ import {
16
16
17
17
type FlexRenderContent < TProps extends NonNullable < unknown > > =
18
18
| string
19
+ | number
19
20
| FlexRenderComponent < TProps >
20
21
| TemplateRef < { $implicit : TProps } >
22
+ | null
21
23
22
24
@Directive ( {
23
25
selector : '[flexRender]' ,
@@ -27,8 +29,11 @@ export class FlexRenderDirective<TProps extends NonNullable<unknown>>
27
29
implements OnInit , DoCheck
28
30
{
29
31
@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
32
37
33
38
@Input ( { required : true , alias : 'flexRenderProps' } )
34
39
props : TProps = { } as TProps
@@ -62,7 +67,7 @@ export class FlexRenderDirective<TProps extends NonNullable<unknown>>
62
67
return null
63
68
}
64
69
65
- if ( typeof content === 'string' ) {
70
+ if ( typeof content === 'string' || typeof content === 'number' ) {
66
71
return this . renderStringContent ( )
67
72
}
68
73
if ( typeof content === 'function' ) {
@@ -72,21 +77,25 @@ export class FlexRenderDirective<TProps extends NonNullable<unknown>>
72
77
}
73
78
74
79
private renderContent ( content : FlexRenderContent < TProps > ) {
75
- if ( typeof content === 'string' ) {
80
+ if ( typeof content === 'string' || typeof content === 'number' ) {
76
81
return this . renderStringContent ( )
77
82
}
78
83
if ( content instanceof TemplateRef ) {
79
84
return this . viewContainerRef . createEmbeddedView (
80
85
content ,
81
86
this . getTemplateRefContext ( )
82
87
)
88
+ } else if ( content instanceof FlexRenderComponent ) {
89
+ return this . renderComponent ( content )
90
+ } else {
91
+ return null
83
92
}
84
- return this . renderComponent ( content )
85
93
}
86
94
87
- private renderStringContent ( ) {
95
+ private renderStringContent ( ) : EmbeddedViewRef < unknown > {
88
96
const context = ( ) => {
89
- return typeof this . content === 'string'
97
+ return typeof this . content === 'string' ||
98
+ typeof this . content === 'number'
90
99
? this . content
91
100
: this . content ?.( this . props )
92
101
}
@@ -97,7 +106,9 @@ export class FlexRenderDirective<TProps extends NonNullable<unknown>>
97
106
} )
98
107
}
99
108
100
- private renderComponent ( flexRenderComponent : FlexRenderComponent < TProps > ) {
109
+ private renderComponent (
110
+ flexRenderComponent : FlexRenderComponent < TProps >
111
+ ) : ComponentRef < unknown > {
101
112
const { component, inputs, injector } = flexRenderComponent
102
113
103
114
const getContext = ( ) => this . props
0 commit comments