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..dd30155f50fb 100644 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -378,6 +378,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 +465,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);