@@ -20,7 +20,6 @@ const COMPONENT_REGEX = /%COMP%/g;
20
20
export const COMPONENT_VARIABLE = "%COMP%" ;
21
21
export const HOST_ATTR = `_nghost-${ COMPONENT_VARIABLE } ` ;
22
22
export const CONTENT_ATTR = `_ngcontent-${ COMPONENT_VARIABLE } ` ;
23
- const ATTR_REPLACER = new RegExp ( escapeRegexSymbols ( CONTENT_ATTR ) , "g" ) ;
24
23
const ATTR_SANITIZER = / - / g;
25
24
26
25
@Injectable ( )
@@ -228,58 +227,45 @@ class EmulatedRenderer extends NativeScriptRenderer {
228
227
private hostAttr : string ;
229
228
230
229
constructor (
231
- private component : RendererType2 ,
230
+ component : RendererType2 ,
232
231
rootView : NgView ,
233
232
zone : NgZone ,
234
233
viewUtil : ViewUtil ,
235
234
) {
236
235
super ( rootView , zone , viewUtil ) ;
237
236
238
- this . addStyles ( ) ;
239
- this . contentAttr = shimContentAttribute ( component . id ) ;
240
- this . hostAttr = shimHostAttribute ( component . id ) ;
237
+ const componentId = component . id . replace ( ATTR_SANITIZER , "_" ) ;
238
+ this . contentAttr = replaceNgAttribute ( CONTENT_ATTR , componentId ) ;
239
+ this . hostAttr = replaceNgAttribute ( HOST_ATTR , componentId ) ;
240
+ this . addStyles ( component . styles , componentId ) ;
241
241
}
242
242
243
243
applyToHost ( view : NgView ) {
244
244
super . setAttribute ( view , this . hostAttr , "" ) ;
245
245
}
246
246
247
247
appendChild ( parent : any , newChild : NgView ) : void {
248
- // Set an attribute to the view to scope component-specific css.
249
- // The property name is pre-generated by Angular.
250
- const cssAttribute = this . replaceNgAttribute ( CONTENT_ATTR ) ;
251
- newChild [ cssAttribute ] = true ;
252
-
253
248
super . appendChild ( parent , newChild ) ;
254
249
}
255
250
256
251
createElement ( parent : any , name : string ) : NgView {
257
252
const view = super . createElement ( parent , name ) ;
253
+
254
+ // Set an attribute to the view to scope component-specific css.
255
+ // The property name is pre-generated by Angular.
258
256
super . setAttribute ( view , this . contentAttr , "" ) ;
259
257
260
258
return view ;
261
259
}
262
260
263
- private addStyles ( ) {
264
- this . component . styles
265
- . map ( s => s . toString ( ) )
266
- . map ( s => this . replaceNgAttribute ( s ) )
261
+ private addStyles ( styles : ( string | any [ ] ) [ ] , componentId : string ) {
262
+ styles . map ( s => s . toString ( ) )
263
+ . map ( s => replaceNgAttribute ( s , componentId ) )
267
264
. forEach ( addCss ) ;
268
265
}
269
266
270
- private replaceNgAttribute ( input : string ) : string {
271
- return input . replace ( ATTR_REPLACER , `_ng_content_${ this . componentId } ` ) ;
272
- }
273
-
274
- private get componentId ( ) : string {
275
- return this . component . id . replace ( ATTR_SANITIZER , "_" ) ;
276
- }
277
- }
278
-
279
- function shimContentAttribute ( componentShortId : string ) : string {
280
- return CONTENT_ATTR . replace ( COMPONENT_REGEX , componentShortId ) ;
281
267
}
282
268
283
- function shimHostAttribute ( componentShortId : string ) : string {
284
- return HOST_ATTR . replace ( COMPONENT_REGEX , componentShortId ) ;
269
+ function replaceNgAttribute ( input : string , componentId : string ) : string {
270
+ return input . replace ( COMPONENT_REGEX , componentId ) ;
285
271
}
0 commit comments