From 96b8d3039cb0d7e1867e2c27717eaf9c2207c8c8 Mon Sep 17 00:00:00 2001 From: Max Martinsson Date: Wed, 6 Jun 2012 16:23:07 +0200 Subject: [PATCH 1/2] fix(compiler): Merging of interpolated class attribute from directive template with replace:true works Closes #1006 --- src/ng/compile.js | 2 +- test/ng/compileSpec.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/ng/compile.js b/src/ng/compile.js index 5c7f14198409..826245396e01 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -990,7 +990,7 @@ function $CompileProvider($provide) { directives.push({ priority: 100, compile: valueFn(function(scope, element, attr) { - if (name === 'class') { + if (name === 'class' && attr[name]) { // we need to interpolate classes again, in the case the element was replaced // and therefore the two class attrs got merged - we want to interpolate the result interpolateFn = $interpolate(attr[name], true); diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 86ba3ade81ab..a94247aa1540 100644 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -1,3 +1,4 @@ + 'use strict'; describe('$compile', function() { @@ -378,6 +379,15 @@ describe('$compile', function() { expect(element).toBe(attr.$$element); } })); + $compileProvider.directive('replaceWithInterpolatedClass', valueFn({ + restrict: 'CAM', + replace: true, + template: '
Replace with interpolated class!
', + compile: function(element, attr) { + attr.$set('compiled', 'COMPILED'); + expect(element).toBe(attr.$$element); + } + })); })); @@ -456,6 +466,13 @@ describe('$compile', function() { })); + it('should handle interpolated css from replacing directive', inject(function($compile, $rootScope) { + element = $compile('
')($rootScope); + $rootScope.$digest(); + expect(element).toHaveClass('class_2'); + })); + + it('should merge interpolated css class', inject(function($compile, $rootScope) { element = $compile('
')($rootScope); From a1abfca9fd113d351ea944c1e2f73ab7c8cee1fc Mon Sep 17 00:00:00 2001 From: Max Martinsson Date: Wed, 6 Jun 2012 16:28:27 +0200 Subject: [PATCH 2/2] fix(compiler): Merging of interpolated class attribute from directive template with replace:true works Closes #1006 --- test/ng/compileSpec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index a94247aa1540..dd30155f50fb 100644 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -1,4 +1,3 @@ - 'use strict'; describe('$compile', function() {