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

fix(compile): Collecting directives from tags that will be replaced #2617

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,8 @@ function $CompileProvider($provide) {

switch(nodeType) {
case 1: /* Element */
// use the node name: <directive>
addDirective(directives,
directiveNormalize(nodeName_(node).toLowerCase()), 'E', maxPriority);

var attributesDirectives = [];
var hasReplaceAttributeDirective = false;
// iterate over the attributes
for (var attr, name, nName, ngAttrName, value, nAttrs = node.attributes,
j = 0, jj = nAttrs && nAttrs.length; j < jj; j++) {
Expand All @@ -534,7 +532,7 @@ function $CompileProvider($provide) {
attrs[nName] = true; // presence means true
}
addAttrInterpolateDirective(node, directives, value, nName);
addDirective(directives, nName, 'A', maxPriority);
addDirective(attributesDirectives, nName, 'A', maxPriority);
}
}

Expand All @@ -543,12 +541,24 @@ function $CompileProvider($provide) {
if (isString(className) && className !== '') {
while (match = CLASS_DIRECTIVE_REGEXP.exec(className)) {
nName = directiveNormalize(match[2]);
if (addDirective(directives, nName, 'C', maxPriority)) {
if (addDirective(attributesDirectives, nName, 'C', maxPriority)) {
attrs[nName] = trim(match[3]);
}
className = className.substr(match.index + match[0].length);
}
}

forEach(attributesDirectives, function(directive) {
hasReplaceAttributeDirective |= directive.replace;
});
if (!hasReplaceAttributeDirective) {
// use the node name: <directive>
addDirective(directives,
directiveNormalize(nodeName_(node).toLowerCase()), 'E', maxPriority);
}
forEach(attributesDirectives, function(directive) {
directives.push(directive);
});
break;
case 3: /* Text Node */
addTextInterpolateDirective(directives, node.nodeValue);
Expand Down
17 changes: 17 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ describe('$compile', function() {
expect(element).toBe(attr.$$element);
}
}));
directive('replaceDirective', valueFn({
replace: true,
template: '<input ng-maxlength="3" />'
}));
}));


Expand Down Expand Up @@ -575,6 +579,19 @@ describe('$compile', function() {
}));


it('should not collect the directive from an element if the element has a' +
' replace directive', inject(function($compile, $rootScope, $sniffer, $browser) {
var element = $compile('<form name="form"><input ng-model="name" name="alias" replace-directive /></form>')($rootScope);

element.find('input').val('aaaa');
browserTrigger(element.find('input'), ($sniffer.hasEvent('input')) ? 'input' : 'change');
expect($rootScope.name).toBe(undefined);
expect($rootScope.form.alias.$valid).toBe(false);

dealoc(element);
}));


it('should merge interpolated css class', inject(function($compile, $rootScope) {
element = $compile('<div class="one {{cls}} three" replace></div>')($rootScope);

Expand Down