@@ -2761,18 +2761,22 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
27612761
27622762 // copy the new attributes on the old attrs object
27632763 forEach ( src , function ( value , key ) {
2764- if ( key === 'class' ) {
2765- safeAddClass ( $element , value ) ;
2766- dst [ 'class' ] = ( dst [ 'class' ] ? dst [ 'class' ] + ' ' : '' ) + value ;
2767- } else if ( key === 'style' ) {
2768- $element . attr ( 'style' , $element . attr ( 'style' ) + ';' + value ) ;
2769- dst [ 'style' ] = ( dst [ 'style' ] ? dst [ 'style' ] + ';' : '' ) + value ;
2770- // `dst` will never contain hasOwnProperty as DOM parser won't let it.
2771- // You will get an "InvalidCharacterError: DOM Exception 5" error if you
2772- // have an attribute like "has-own-property" or "data-has-own-property", etc.
2773- } else if ( key . charAt ( 0 ) !== '$' && ! dst . hasOwnProperty ( key ) ) {
2774- dst [ key ] = value ;
2775- dstAttr [ key ] = srcAttr [ key ] ;
2764+ // Check if we already set this attribute in the loop above
2765+ if ( ! dst [ key ] ) {
2766+
2767+ if ( key === 'class' ) {
2768+ safeAddClass ( $element , value ) ;
2769+ dst [ 'class' ] = ( dst [ 'class' ] ? dst [ 'class' ] + ' ' : '' ) + value ;
2770+ } else if ( key === 'style' ) {
2771+ $element . attr ( 'style' , $element . attr ( 'style' ) + ';' + value ) ;
2772+ dst [ 'style' ] = ( dst [ 'style' ] ? dst [ 'style' ] + ';' : '' ) + value ;
2773+ // `dst` will never contain hasOwnProperty as DOM parser won't let it.
2774+ // You will get an "InvalidCharacterError: DOM Exception 5" error if you
2775+ // have an attribute like "has-own-property" or "data-has-own-property", etc.
2776+ } else if ( key . charAt ( 0 ) !== '$' && ! dst . hasOwnProperty ( key ) ) {
2777+ dst [ key ] = value ;
2778+ dstAttr [ key ] = srcAttr [ key ] ;
2779+ }
27762780 }
27772781 } ) ;
27782782 }
0 commit comments