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

Commit 8e6e3eb

Browse files
JamieMasonbtford
authored andcommitted
fix($compile): ng-attr to support dash separated attribute names
1 parent ac72bee commit 8e6e3eb

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ function $CompileProvider($provide) {
631631
// support ngAttr attribute binding
632632
ngAttrName = directiveNormalize(name);
633633
if (NG_ATTR_BINDING.test(ngAttrName)) {
634-
name = ngAttrName.substr(6).toLowerCase();
634+
name = snake_case(ngAttrName.substr(6), '-');
635635
}
636636

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

test/jqLiteSpec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,7 @@ describe('jqLite', function() {
13661366
expect(camelCase('-moz-foo-bar')).toBe('MozFooBar');
13671367
expect(camelCase('-webkit-foo-bar')).toBe('webkitFooBar');
13681368
expect(camelCase('-webkit-foo-bar')).toBe('webkitFooBar');
1369-
})
1369+
});
13701370
});
1371+
13711372
});

test/ng/compileSpec.js

+29
Original file line numberDiff line numberDiff line change
@@ -3342,6 +3342,35 @@ describe('$compile', function() {
33423342
expect(element.attr('test3')).toBe('Misko');
33433343
expect(element.attr('test4')).toBe('Misko');
33443344
}));
3345+
3346+
describe('when an attribute has a dash-separated name', function () {
3347+
3348+
it('should work with different prefixes', inject(function($compile, $rootScope) {
3349+
$rootScope.name = "JamieMason";
3350+
element = $compile('<span ng:attr:dash-test="{{name}}" ng-Attr-dash-test2="{{name}}" ng_Attr_dash-test3="{{name}}"></span>')($rootScope);
3351+
expect(element.attr('dash-test')).toBeUndefined();
3352+
expect(element.attr('dash-test2')).toBeUndefined();
3353+
expect(element.attr('dash-test3')).toBeUndefined();
3354+
$rootScope.$digest();
3355+
expect(element.attr('dash-test')).toBe('JamieMason');
3356+
expect(element.attr('dash-test2')).toBe('JamieMason');
3357+
expect(element.attr('dash-test3')).toBe('JamieMason');
3358+
}));
3359+
3360+
it('should work if they are prefixed with x- or data-', inject(function($compile, $rootScope) {
3361+
$rootScope.name = "JamieMason";
3362+
element = $compile('<span data-ng-attr-dash-test2="{{name}}" x-ng-attr-dash-test3="{{name}}" data-ng:attr-dash-test4="{{name}}"></span>')($rootScope);
3363+
expect(element.attr('dash-test2')).toBeUndefined();
3364+
expect(element.attr('dash-test3')).toBeUndefined();
3365+
expect(element.attr('dash-test4')).toBeUndefined();
3366+
$rootScope.$digest();
3367+
expect(element.attr('dash-test2')).toBe('JamieMason');
3368+
expect(element.attr('dash-test3')).toBe('JamieMason');
3369+
expect(element.attr('dash-test4')).toBe('JamieMason');
3370+
}));
3371+
3372+
});
3373+
33453374
});
33463375

33473376

0 commit comments

Comments
 (0)