@@ -4,14 +4,17 @@ import {
4
4
ComponentFactoryResolver ,
5
5
ContentChild ,
6
6
DoCheck ,
7
+ ElementRef ,
7
8
EventEmitter ,
8
9
Inject ,
9
10
Input ,
10
11
KeyValueDiffer ,
11
12
KeyValueDiffers ,
12
13
OnChanges ,
13
14
OnDestroy ,
15
+ OnInit ,
14
16
Output ,
17
+ Renderer2 ,
15
18
SimpleChanges ,
16
19
Type ,
17
20
ViewChild ,
@@ -43,11 +46,12 @@ function getPlaceholder(rendering: ComponentRendering, name: string) {
43
46
<ng-template #view></ng-template>
44
47
` ,
45
48
} )
46
- export class PlaceholderComponent implements OnChanges , DoCheck , OnDestroy {
49
+ export class PlaceholderComponent implements OnInit , OnChanges , DoCheck , OnDestroy {
47
50
private _inputs : { [ key : string ] : any } ;
48
51
private _differ : KeyValueDiffer < string , any > ;
49
52
private _componentInstances : any [ ] = [ ] ;
50
53
private destroyed = false ;
54
+ private parentStyleAttribute : string = '' ;
51
55
public isLoading = true ;
52
56
53
57
@Input ( ) name ?: string ;
@@ -76,9 +80,26 @@ export class PlaceholderComponent implements OnChanges, DoCheck, OnDestroy {
76
80
private differs : KeyValueDiffers ,
77
81
private componentFactory : JssComponentFactoryService ,
78
82
private changeDetectorRef : ChangeDetectorRef ,
83
+ private elementRef : ElementRef ,
84
+ private renderer : Renderer2 ,
79
85
@Inject ( PLACEHOLDER_MISSING_COMPONENT_COMPONENT ) private missingComponentComponent : Type < any >
80
86
) { }
81
87
88
+ ngOnInit ( ) {
89
+ // just to ensure the element exists
90
+ const elem = this . elementRef . nativeElement ;
91
+
92
+ if ( elem ) {
93
+ const attributes : NamedNodeMap = elem . attributes ;
94
+ for ( let i = 0 ; i < attributes . length ; i ++ ) {
95
+ const attr : Attr | null = attributes . item ( i ) ;
96
+ if ( attr && attr . name . indexOf ( '_ngcontent' ) !== - 1 ) {
97
+ this . parentStyleAttribute = attr . name ;
98
+ }
99
+ }
100
+ }
101
+ }
102
+
82
103
ngOnDestroy ( ) {
83
104
this . destroyed = true ;
84
105
this . _componentInstances = [ ] ;
@@ -199,7 +220,14 @@ export class PlaceholderComponent implements OnChanges, DoCheck, OnDestroy {
199
220
const componentFactory =
200
221
rendering . componentFactory || this . componentFactoryResolver . resolveComponentFactory ( rendering . componentImplementation ) ;
201
222
202
- const componentInstance = this . view . createComponent ( componentFactory , index ) . instance ;
223
+ // apply the parent style attribute _ngcontent
224
+ // work-around for https://github.com/angular/angular/issues/12215
225
+ const createdComponentRef = this . view . createComponent ( componentFactory , index ) ;
226
+ if ( this . parentStyleAttribute ) {
227
+ this . renderer . setAttribute ( createdComponentRef . location . nativeElement , this . parentStyleAttribute , '' ) ;
228
+ }
229
+
230
+ const componentInstance = createdComponentRef . instance ;
203
231
componentInstance . rendering = rendering . componentDefinition ;
204
232
if ( this . _inputs ) {
205
233
this . _setComponentInputs ( componentInstance , this . _inputs ) ;
0 commit comments