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

Commit 23c8a90

Browse files
committed
fix($compile): support class directives on SVG elements
Closes #10736 Closes #10756
1 parent 0504395 commit 23c8a90

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/ng/compile.js

+4
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
14501450

14511451
// use class as directive
14521452
className = node.className;
1453+
if (isObject(className)) {
1454+
// Maybe SVGAnimatedString
1455+
className = className.animVal;
1456+
}
14531457
if (isString(className) && className !== '') {
14541458
while (match = CLASS_DIRECTIVE_REGEXP.exec(className)) {
14551459
nName = directiveNormalize(match[2]);

test/ng/compileSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,17 @@ describe('$compile', function() {
443443
}));
444444

445445

446+
it('should allow directives in SVG element classes', inject(function($compile, $rootScope, log) {
447+
if (!window.SVGElement) return;
448+
element = $compile('<svg><text class="greet: angular; log:123;"></text></svg>')($rootScope);
449+
var text = element.children().eq(0);
450+
// In old Safari, SVG elements don't have innerHTML, so element.html() won't work
451+
// (https://bugs.webkit.org/show_bug.cgi?id=136903)
452+
expect(text.text()).toEqual('Hello angular');
453+
expect(log).toEqual('123');
454+
}));
455+
456+
446457
it('should ignore not set CSS classes on SVG elements', inject(function($compile, $rootScope, log) {
447458
if (!window.SVGElement) return;
448459
// According to spec SVG element className property is readonly, but only FF

0 commit comments

Comments
 (0)