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

Commit d122143

Browse files
Wesley Chowesleycho
Wesley Cho
authored andcommitted
feat($compile): Add support for ng-attr with camelcased attributes
- Modify $compile to handle camelcased attributes only with ng-attr to support SVG fully - Change to svg to make clear it works - Ensure the elements and attributes used are valid SVG elements & attributes - Modify in attempt to use attribute IE is happy with - Add specific SVG check for IE - Fix incorrect attribute value used Modification to re-run tests - Break up line for jshint - Fix codestyle - Replace with prefix regexp
1 parent e9b9421 commit d122143

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/ng/compile.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
14051405
// support ngAttr attribute binding
14061406
ngAttrName = directiveNormalize(name);
14071407
if (isNgAttr = NG_ATTR_BINDING.test(ngAttrName)) {
1408-
name = snake_case(ngAttrName.substr(6), '-');
1408+
name = name.replace(PREFIX_REGEXP, '')
1409+
.substr(8).replace(/_(.)/g, function(match, letter) {
1410+
return letter.toUpperCase();
1411+
});
14091412
}
14101413

14111414
var directiveNName = ngAttrName.replace(/(Start|End)$/, '');

test/ng/compileSpec.js

+29
Original file line numberDiff line numberDiff line change
@@ -6619,6 +6619,35 @@ describe('$compile', function() {
66196619
});
66206620

66216621

6622+
describe('when an attribute has an underscore-separated name', function() {
6623+
6624+
it('should work with different prefixes', inject(function($compile, $rootScope) {
6625+
$rootScope.dimensions = "0 0 0 0";
6626+
element = $compile('<svg ng:attr:view_box="{{dimensions}}"></svg>')($rootScope);
6627+
expect(element.attr('viewBox')).toBeUndefined();
6628+
$rootScope.$digest();
6629+
expect(element.attr('viewBox')).toBe('0 0 0 0');
6630+
}));
6631+
6632+
it('should work if they are prefixed with x- or data-', inject(function($compile, $rootScope) {
6633+
$rootScope.dimensions = "0 0 0 0";
6634+
$rootScope.number = 0.42;
6635+
$rootScope.scale = 1;
6636+
element = $compile('<svg data-ng-attr-view_box="{{dimensions}}">' +
6637+
'<filter x-ng-attr-filter_units="{{number}}">' +
6638+
'<feDiffuseLighting data-ng:attr_surface_scale="{{scale}}">' +
6639+
'</feDiffuseLighting>' +
6640+
'<feSpecularLighting x-ng:attr_surface_scale="{{scale}}">' +
6641+
'</feSpecularLighting></filter></svg>')($rootScope);
6642+
expect(element.attr('viewBox')).toBeUndefined();
6643+
$rootScope.$digest();
6644+
expect(element.attr('viewBox')).toBe('0 0 0 0');
6645+
expect(element.find('filter').attr('filterUnits')).toBe('0.42');
6646+
expect(element.find('feDiffuseLighting').attr('surfaceScale')).toBe('1');
6647+
expect(element.find('feSpecularLighting').attr('surfaceScale')).toBe('1');
6648+
}));
6649+
});
6650+
66226651
describe('multi-element directive', function() {
66236652
it('should group on link function', inject(function($compile, $rootScope) {
66246653
$rootScope.show = false;

0 commit comments

Comments
 (0)