Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit daf8a56

Browse files
committedAug 19, 2015
fix($compile): backport to 1.2 of workaround for IE11 MutationObserver
Backport #11796 to 1.2 branch. IE11 MutationObserver breaks consecutive text nodes into several text nodes. This patch merges consecutive text nodes into a single node before looking for interpolations. Closes #11781
1 parent b041b66 commit daf8a56

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
 

‎src/ng/compile.js

+7
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
10881088
}
10891089
break;
10901090
case 3: /* Text Node */
1091+
if (msie === 11) {
1092+
// Workaround for #11781
1093+
while (node.parentNode && node.nextSibling && node.nextSibling.nodeType === 3 /* Text Node */) {
1094+
node.nodeValue = node.nodeValue + node.nextSibling.nodeValue;
1095+
node.parentNode.removeChild(node.nextSibling);
1096+
}
1097+
}
10911098
addTextInterpolateDirective(directives, node.nodeValue);
10921099
break;
10931100
case 8: /* Comment */

‎test/ng/compileSpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -2214,6 +2214,23 @@ describe('$compile', function() {
22142214
'</select>');
22152215
}));
22162216

2217+
it('should handle consecutive text elements as a single text element', inject(function($rootScope, $compile) {
2218+
// No point it running the test, if there is no MutationObserver
2219+
if (!window.MutationObserver) return;
2220+
2221+
// Create and register the MutationObserver
2222+
var observer = new window.MutationObserver(noop);
2223+
observer.observe(document.body, {childList: true, subtree: true});
2224+
2225+
// Run the actual test
2226+
var base = jqLite('<div>&mdash; {{ "This doesn\'t." }}</div>');
2227+
element = $compile(base)($rootScope);
2228+
$rootScope.$digest();
2229+
expect(element.text()).toBe("— This doesn't.");
2230+
2231+
// Unregister the MutationObserver (and hope it doesn't mess up with subsequent tests)
2232+
observer.disconnect();
2233+
}));
22172234

22182235
it('should support custom start/end interpolation symbols in template and directive template',
22192236
function() {

0 commit comments

Comments
 (0)
This repository has been archived.