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

Commit c47abd0

Browse files
committed
fix(ngInclude): allow ngInclude to load scripts when jQuery is included
In 1.2, the behavior of ngInclude was modified to use DOM APIs rather than jqLite. This means that even when jQuery was loaded, ngInclude was not calling into it, and thus scripts were not eval'd as they had been before. Although the use of ngInclude to eval scripts as a lazy-loading strategy was never an intentional feature, this patch restores the ability to do so. Closes #3756
1 parent 68d71bb commit c47abd0

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

src/ng/animate.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,14 @@ var $AnimateProvider = ['$provide', function($provide) {
9999
* inserted into the DOM
100100
*/
101101
enter : function(element, parent, after, done) {
102-
var afterNode = after && after[after.length - 1];
103-
var parentNode = parent && parent[0] || afterNode && afterNode.parentNode;
104-
// IE does not like undefined so we have to pass null.
105-
var afterNextSibling = (afterNode && afterNode.nextSibling) || null;
106-
forEach(element, function(node) {
107-
parentNode.insertBefore(node, afterNextSibling);
108-
});
102+
if (after) {
103+
after.after(element);
104+
} else {
105+
if (!parent || !parent[0]) {
106+
parent = after.parent();
107+
}
108+
parent.append(element);
109+
}
109110
done && $timeout(done, 0, false);
110111
},
111112

test/ng/directive/ngIncludeSpec.js

+25
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,31 @@ describe('ngInclude', function() {
312312
}));
313313

314314

315+
it('should exec scripts when jQuery is included', inject(function($compile, $rootScope, $httpBackend) {
316+
if (!jQuery) {
317+
return;
318+
}
319+
320+
element = $compile('<div><span ng-include="includeUrl"></span></div>')($rootScope);
321+
322+
// the element needs to be appended for the script to run
323+
element.appendTo(document.body);
324+
window._ngIncludeCausesScriptToRun = false;
325+
$httpBackend.expect('GET', 'url1').respond('<script>window._ngIncludeCausesScriptToRun = true;</script>');
326+
$rootScope.includeUrl = 'url1';
327+
$rootScope.$digest();
328+
$httpBackend.flush();
329+
330+
expect(window._ngIncludeCausesScriptToRun).toBe(true);
331+
332+
// IE8 doesn't like deleting properties of window
333+
window._ngIncludeCausesScriptToRun = undefined;
334+
try {
335+
delete window._ngIncludeCausesScriptToRun;
336+
} catch (e) {}
337+
}));
338+
339+
315340
describe('autoscroll', function() {
316341
var autoScrollSpy;
317342

0 commit comments

Comments
 (0)