From 3fd5c63476f5009b154d5a30d0f70c7278f3f79d Mon Sep 17 00:00:00 2001 From: Viktor Rutberg Date: Thu, 13 Feb 2014 15:05:40 +0100 Subject: [PATCH] fix($compile): fix duplicate style attributes This fix avoids duplicating style attributes in directives that specify 'replace: true' and 'template:
'. Closes #6239 --- src/ng/compile.js | 4 +++- test/ng/compileSpec.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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);