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

Commit 94dd685

Browse files
committed
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.
1 parent dc32ea6 commit 94dd685

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

src/ng/directive/script.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ var scriptDirective = ['$templateCache', function($templateCache) {
3535
terminal: true,
3636
compile: function(element, attr) {
3737
if (attr.type == 'text/ng-template') {
38-
var templateUrl = attr.id;
39-
$templateCache.put(templateUrl, element.text());
38+
var templateUrl = attr.id,
39+
// IE is not consistent, in scripts we have to read .text but in other nodes we have to read .textContent
40+
text = element[0].text;
41+
42+
$templateCache.put(templateUrl, text);
4043
}
4144
}
4245
};

test/ng/directive/scriptSpec.js

+6-11
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ describe('scriptDirective', function() {
1111

1212
it('should populate $templateCache with contents of a ng-template script element', inject(
1313
function($compile, $templateCache) {
14-
if (msie <=8) return;
15-
// in ie8 it is not possible to create a script tag with the right content.
16-
// it always comes up as empty. I was trying to set the text of the
17-
// script tag, but that did not work either, so I gave up.
1814
$compile('<div>foo' +
1915
'<script id="/ignore">ignore me</script>' +
2016
'<script type="text/ng-template" id="/myTemplate.html"><x>{{y}}</x></script>' +
@@ -26,19 +22,18 @@ describe('scriptDirective', function() {
2622

2723

2824
it('should not compile scripts', inject(function($compile, $templateCache, $rootScope) {
29-
if (msie <=8) return; // see above
30-
3125
var doc = jqLite('<div></div>');
32-
// jQuery is too smart and removes
33-
doc[0].innerHTML = '<script type="text/javascript">some {{binding}}</script>' +
34-
'<script type="text/ng-template" id="/some">other {{binding}}</script>';
26+
// jQuery is too smart and removes script tags
27+
doc[0].innerHTML = 'foo' +
28+
'<script type="text/javascript">some {{binding}}</script>' +
29+
'<script type="text/ng-template" id="/some">other {{binding}}</script>';
3530

3631
$compile(doc)($rootScope);
3732
$rootScope.$digest();
3833

3934
var scripts = doc.find('script');
40-
expect(scripts.eq(0).text()).toBe('some {{binding}}');
41-
expect(scripts.eq(1).text()).toBe('other {{binding}}');
35+
expect(scripts.eq(0)[0].text).toBe('some {{binding}}');
36+
expect(scripts.eq(1)[0].text).toBe('other {{binding}}');
4237
dealoc(doc);
4338
}));
4439
});

0 commit comments

Comments
 (0)