From df695c3565a415adb742fb7de0dff69c5e2af435 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Wed, 14 Jan 2015 17:38:26 -0500 Subject: [PATCH] fix($compile): support class directives on SVG elements Closes #10736 --- src/ng/compile.js | 4 ++++ test/ng/compileSpec.js | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/ng/compile.js b/src/ng/compile.js index 7b2dde884926..bef8873816d1 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -1450,6 +1450,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { // use class as directive className = node.className; + if (isObject(className)) { + // Maybe SVGAnimatedString + className = className.animVal; + } if (isString(className) && className !== '') { while (match = CLASS_DIRECTIVE_REGEXP.exec(className)) { nName = directiveNormalize(match[2]); diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 1e4717add671..5df9bddb79c5 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -443,6 +443,17 @@ describe('$compile', function() { })); + it('should allow directives in SVG element classes', inject(function($compile, $rootScope, log) { + if (!window.SVGElement) return; + element = $compile('')($rootScope); + var text = element.children().eq(0); + // In old Safari, SVG elements don't have innerHTML, so element.html() won't work + // (https://bugs.webkit.org/show_bug.cgi?id=136903) + expect(text.text()).toEqual('Hello angular'); + expect(log).toEqual('123'); + })); + + it('should ignore not set CSS classes on SVG elements', inject(function($compile, $rootScope, log) { if (!window.SVGElement) return; // According to spec SVG element className property is readonly, but only FF