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

Commit 09e2eb6

Browse files
devversionThomasBurleson
authored andcommitted
fix(subheader): do not compile ng-repeat twice.
* The subheader component always compiles the outerHTML of the root element (replaced) twice, to be able to create a sticky clone. * When using ng-repeat on the subheader element, the ngRepeat wil be compiled again and it will result in another repetition. Fixes #8647. Closes #9187
1 parent 7223d3e commit 09e2eb6

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

src/components/subheader/subheader.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ function MdSubheaderDirective($mdSticky, $compile, $mdTheming, $mdUtil) {
5656
link: function postLink(scope, element, attr, controllers, transclude) {
5757
$mdTheming(element);
5858
element.addClass('_md');
59-
59+
60+
// Remove the ngRepeat attribute from the root element, because we don't want to compile
61+
// the ngRepeat for the sticky clone again.
62+
$mdUtil.prefixer().removeAttribute(element, 'ng-repeat');
63+
6064
var outerHTML = element[0].outerHTML;
6165

6266
function getContent(el) {

src/components/subheader/subheader.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ describe('mdSubheader', function() {
166166
'</div>'
167167
);
168168

169-
// TODO(devversion): Remove this expectation and update to correctly detect 6 subheaders
170-
// TODO(devversion) See related issue: https://github.com/angular/material/issues/8647
171-
expect(contentElement[0].querySelectorAll('.md-subheader').length).toEqual(12);
169+
expect(contentElement[0].querySelectorAll('.md-subheader').length).toEqual(6);
172170

173171
// Check if there were no exceptions caused.
174172
expect($exceptionHandler.errors).toEqual([]);

src/core/util/prefixer.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ function MdPrefixer(initialAttributes, buildSelector) {
2222
return {
2323
buildList: _buildList,
2424
buildSelector: _buildSelector,
25-
hasAttribute: _hasAttribute
25+
hasAttribute: _hasAttribute,
26+
removeAttribute: _removeAttribute
2627
};
2728

2829
function _buildList(attributes) {
@@ -41,7 +42,7 @@ function MdPrefixer(initialAttributes, buildSelector) {
4142
attributes = angular.isArray(attributes) ? attributes : [attributes];
4243

4344
return _buildList(attributes)
44-
.map(function (item) {
45+
.map(function(item) {
4546
return '[' + item + ']'
4647
})
4748
.join(',');
@@ -60,4 +61,12 @@ function MdPrefixer(initialAttributes, buildSelector) {
6061

6162
return false;
6263
}
64+
65+
function _removeAttribute(element, attribute) {
66+
element = element[0] || element;
67+
68+
_buildList(attribute).forEach(function(prefixedAttribute) {
69+
element.removeAttribute(prefixedAttribute);
70+
});
71+
}
6372
}

src/core/util/prefixer.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,34 @@ describe('prefixer', function() {
7676

7777
});
7878

79+
describe('and removing an attribute', function() {
80+
81+
it('should remove a prefixed attribute', function() {
82+
var element = angular.element('<div data-ng-click="null">')[0];
83+
84+
prefixer.removeAttribute(element, 'ng-click');
85+
86+
expect(element.hasAttribute('data-ng-click')).toBeFalsy();
87+
});
88+
89+
it('should remove an un-prefixed attribute', function() {
90+
var element = angular.element('<div ng-click="null">')[0];
91+
92+
prefixer.removeAttribute(element, 'ng-click');
93+
94+
expect(element.hasAttribute('ng-click')).toBeFalsy();
95+
});
96+
97+
it('should remove prefixed and un-prefixed attributes', function() {
98+
var element = angular.element('<div ng-click="null" data-ng-click="null">')[0];
99+
100+
prefixer.removeAttribute(element, 'ng-click');
101+
102+
expect(prefixer.hasAttribute(element, 'ng-click')).toBeFalsy();
103+
});
104+
105+
});
106+
79107
});
80108

81109
});

0 commit comments

Comments
 (0)