Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7f629ba

Browse files
committedAug 18, 2015
fix($compile): backport to 1.2 of workaround for IE11 MutationObserver
Backport angular#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 angular#11781
1 parent b041b66 commit 7f629ba

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed
 

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"url": "https://github.com/angular/angular.js.git"
77
},
88
"devDependencies": {
9+
"i": "~0.3.3",
910
"angular-benchpress": "0.x.x",
1011
"benchmark": "1.x.x",
1112
"bower": "~1.3.9",

‎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)
Please sign in to comment.