@@ -143,11 +143,16 @@ class DefaultServerRenderer2 implements Renderer2 {
143143 removeClass ( el : any , name : string ) : void { el . classList . remove ( name ) ; }
144144
145145 setStyle ( el : any , style : string , value : any , flags : RendererStyleFlags2 ) : void {
146- getDOM ( ) . setStyle ( el , style , value ) ;
146+ style = style . replace ( / ( [ a - z ] ) ( [ A - Z ] ) / g, '$1-$2' ) . toLowerCase ( ) ;
147+ const styleMap = _readStyleAttribute ( el ) ;
148+ styleMap [ style ] = value || '' ;
149+ _writeStyleAttribute ( el , styleMap ) ;
147150 }
148151
149152 removeStyle ( el : any , style : string , flags : RendererStyleFlags2 ) : void {
150- getDOM ( ) . removeStyle ( el , style ) ;
153+ // IE requires '' instead of null
154+ // see https://github.com/angular/angular/issues/7916
155+ this . setStyle ( el , style , '' , flags ) ;
151156 }
152157
153158 // The value was validated already as a property binding, against the property name.
@@ -246,3 +251,34 @@ class EmulatedEncapsulationServerRenderer2 extends DefaultServerRenderer2 {
246251 return el ;
247252 }
248253}
254+
255+ function _readStyleAttribute ( element : any ) : { [ name : string ] : string } {
256+ const styleMap : { [ name : string ] : string } = { } ;
257+ const styleAttribute = element . getAttribute ( 'style' ) ;
258+ if ( styleAttribute ) {
259+ const styleList = styleAttribute . split ( / ; + / g) ;
260+ for ( let i = 0 ; i < styleList . length ; i ++ ) {
261+ const style = styleList [ i ] . trim ( ) ;
262+ if ( style . length > 0 ) {
263+ const colonIndex = style . indexOf ( ':' ) ;
264+ if ( colonIndex === - 1 ) {
265+ throw new Error ( `Invalid CSS style: ${ style } ` ) ;
266+ }
267+ const name = style . substr ( 0 , colonIndex ) . trim ( ) ;
268+ styleMap [ name ] = style . substr ( colonIndex + 1 ) . trim ( ) ;
269+ }
270+ }
271+ }
272+ return styleMap ;
273+ }
274+
275+ function _writeStyleAttribute ( element : any , styleMap : { [ name : string ] : string } ) {
276+ let styleAttrValue = '' ;
277+ for ( const key in styleMap ) {
278+ const newValue = styleMap [ key ] ;
279+ if ( newValue ) {
280+ styleAttrValue += key + ':' + styleMap [ key ] + ';' ;
281+ }
282+ }
283+ element . setAttribute ( 'style' , styleAttrValue ) ;
284+ }
0 commit comments