Skip to content

Commit 96b8d30

Browse files
committed
fix(compiler): Merging of interpolated class attribute from directive template with replace:true works
Closes angular#1006
1 parent a57141f commit 96b8d30

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ function $CompileProvider($provide) {
990990
directives.push({
991991
priority: 100,
992992
compile: valueFn(function(scope, element, attr) {
993-
if (name === 'class') {
993+
if (name === 'class' && attr[name]) {
994994
// we need to interpolate classes again, in the case the element was replaced
995995
// and therefore the two class attrs got merged - we want to interpolate the result
996996
interpolateFn = $interpolate(attr[name], true);

test/ng/compileSpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
'use strict';
23

34
describe('$compile', function() {
@@ -378,6 +379,15 @@ describe('$compile', function() {
378379
expect(element).toBe(attr.$$element);
379380
}
380381
}));
382+
$compileProvider.directive('replaceWithInterpolatedClass', valueFn({
383+
restrict: 'CAM',
384+
replace: true,
385+
template: '<div class="class_{{1+1}}">Replace with interpolated class!</div>',
386+
compile: function(element, attr) {
387+
attr.$set('compiled', 'COMPILED');
388+
expect(element).toBe(attr.$$element);
389+
}
390+
}));
381391
}));
382392

383393

@@ -456,6 +466,13 @@ describe('$compile', function() {
456466
}));
457467

458468

469+
it('should handle interpolated css from replacing directive', inject(function($compile, $rootScope) {
470+
element = $compile('<div replace-with-interpolated-class></div>')($rootScope);
471+
$rootScope.$digest();
472+
expect(element).toHaveClass('class_2');
473+
}));
474+
475+
459476
it('should merge interpolated css class', inject(function($compile, $rootScope) {
460477
element = $compile('<div class="one {{cls}} three" replace></div>')($rootScope);
461478

0 commit comments

Comments
 (0)