From 94dd68570952f6f31abfa351b1159afcd3588a57 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 17 Apr 2012 13:55:10 -0700 Subject: [PATCH] fix(script): Incorrectly reading script text on ie IE deals with script tags in special way and .text() does not work. Reading the .text property directly fixes the issue. --- src/ng/directive/script.js | 7 +++++-- test/ng/directive/scriptSpec.js | 17 ++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/ng/directive/script.js b/src/ng/directive/script.js index dcbd97b18a7e..79f8b26e206a 100644 --- a/src/ng/directive/script.js +++ b/src/ng/directive/script.js @@ -35,8 +35,11 @@ var scriptDirective = ['$templateCache', function($templateCache) { terminal: true, compile: function(element, attr) { if (attr.type == 'text/ng-template') { - var templateUrl = attr.id; - $templateCache.put(templateUrl, element.text()); + var templateUrl = attr.id, + // IE is not consistent, in scripts we have to read .text but in other nodes we have to read .textContent + text = element[0].text; + + $templateCache.put(templateUrl, text); } } }; diff --git a/test/ng/directive/scriptSpec.js b/test/ng/directive/scriptSpec.js index 471e04ce0c66..73128765a9a2 100644 --- a/test/ng/directive/scriptSpec.js +++ b/test/ng/directive/scriptSpec.js @@ -11,10 +11,6 @@ describe('scriptDirective', function() { it('should populate $templateCache with contents of a ng-template script element', inject( function($compile, $templateCache) { - if (msie <=8) return; - // in ie8 it is not possible to create a script tag with the right content. - // it always comes up as empty. I was trying to set the text of the - // script tag, but that did not work either, so I gave up. $compile('
foo' + '' + '' + @@ -26,19 +22,18 @@ describe('scriptDirective', function() { it('should not compile scripts', inject(function($compile, $templateCache, $rootScope) { - if (msie <=8) return; // see above - var doc = jqLite('
'); - // jQuery is too smart and removes - doc[0].innerHTML = '' + - ''; + // jQuery is too smart and removes script tags + doc[0].innerHTML = 'foo' + + '' + + ''; $compile(doc)($rootScope); $rootScope.$digest(); var scripts = doc.find('script'); - expect(scripts.eq(0).text()).toBe('some {{binding}}'); - expect(scripts.eq(1).text()).toBe('other {{binding}}'); + expect(scripts.eq(0)[0].text).toBe('some {{binding}}'); + expect(scripts.eq(1)[0].text).toBe('other {{binding}}'); dealoc(doc); })); });