mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-20 00:10:26 +00:00
fix($compile): correctly merge class attr for replace directives
Merging of interpolated class attribute from directive template with replace:true works Closes #1006
This commit is contained in:
parent
10f80d7d29
commit
fb99b539b4
2 changed files with 19 additions and 0 deletions
|
|
@ -865,6 +865,7 @@ function $CompileProvider($provide) {
|
|||
var srcAttr = src.$attr,
|
||||
dstAttr = dst.$attr,
|
||||
$element = dst.$$element;
|
||||
|
||||
// reapply the old attributes to the new element
|
||||
forEach(dst, function(value, key) {
|
||||
if (key.charAt(0) != '$') {
|
||||
|
|
@ -874,10 +875,12 @@ function $CompileProvider($provide) {
|
|||
dst.$set(key, value, true, srcAttr[key]);
|
||||
}
|
||||
});
|
||||
|
||||
// copy the new attributes on the old attrs object
|
||||
forEach(src, function(value, key) {
|
||||
if (key == 'class') {
|
||||
safeAddClass($element, value);
|
||||
dst['class'] = (dst['class'] ? dst['class'] + ' ' : '') + value;
|
||||
} else if (key == 'style') {
|
||||
$element.attr('style', $element.attr('style') + ';' + value);
|
||||
} else if (key.charAt(0) != '$' && !dst.hasOwnProperty(key)) {
|
||||
|
|
|
|||
|
|
@ -388,6 +388,14 @@ describe('$compile', function() {
|
|||
expect(element).toBe(attr.$$element);
|
||||
}
|
||||
}));
|
||||
directive('replaceWithInterpolatedClass', valueFn({
|
||||
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);
|
||||
}
|
||||
}));
|
||||
}));
|
||||
|
||||
|
||||
|
|
@ -466,6 +474,14 @@ 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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue