Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix(compiler): Merging of interpolated class attribute from directive template with replace:true works #1022

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,15 @@ describe('$compile', function() {
expect(element).toBe(attr.$$element);
}
}));
$compileProvider.directive('replaceWithInterpolatedClass', valueFn({
restrict: 'CAM',
replace: true,
template: '<div class="class_{{1+1}}">Replace with interpolated class!</div>',
compile: function(element, attr) {
attr.$set('compiled', 'COMPILED');
expect(element).toBe(attr.$$element);
}
}));
}));


Expand Down Expand Up @@ -456,6 +465,13 @@ describe('$compile', function() {
}));


it('should handle interpolated css from replacing directive', inject(function($compile, $rootScope) {
element = $compile('<div replace-with-interpolated-class></div>')($rootScope);
$rootScope.$digest();
expect(element).toHaveClass('class_2');
}));


it('should merge interpolated css class', inject(function($compile, $rootScope) {
element = $compile('<div class="one {{cls}} three" replace></div>')($rootScope);

Expand Down