diff --git a/src/ng/compile.js b/src/ng/compile.js index 58c3b5fc6f37..5f499f8e037e 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -1645,7 +1645,9 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { safeAddClass($element, value); dst['class'] = (dst['class'] ? dst['class'] + ' ' : '') + value; } else if (key == 'style') { - $element.attr('style', $element.attr('style') + ';' + value); + if($element.attr("style") !== value) { + $element.attr('style', $element.attr('style') + ';' + value); + } dst['style'] = (dst['style'] ? dst['style'] + ';' : '') + value; // `dst` will never contain hasOwnProperty as DOM parser won't let it. // You will get an "InvalidCharacterError: DOM Exception 5" error if you diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 96d3c18bc7ee..7a9b1a4c493d 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -541,6 +541,14 @@ describe('$compile', function() { replace: true, template: 'TD' })); + directive('replaceWithNonInterpolatedStyle', valueFn({ + replace: true, + template: '
Replace with non-interpolated style!
', + compile: function(element, attr) { + attr.$set('compiled', 'COMPILED'); + expect(element).toBe(attr.$$element); + } + })); })); @@ -635,6 +643,13 @@ describe('$compile', function() { })); } + it('should handle non-interpolated css style from replacing directive', inject( + function($compile, $rootScope) { + element = $compile('
')($rootScope); + $rootScope.$digest(); + expect(element.attr('style')).toMatch(/^color\: red;?$/ig); + })); + it('should merge interpolated css class', inject(function($compile, $rootScope) { element = $compile('
')($rootScope);