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

Commit

Permalink
fix(ngInclude): allow ngInclude to load scripts when jQuery is included
Browse files Browse the repository at this point in the history
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
  • Loading branch information
btford committed Nov 20, 2013
1 parent 68d71bb commit c47abd0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/ng/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,14 @@ var $AnimateProvider = ['$provide', function($provide) {
* inserted into the DOM
*/
enter : function(element, parent, after, done) {
var afterNode = after && after[after.length - 1];
var parentNode = parent && parent[0] || afterNode && afterNode.parentNode;
// IE does not like undefined so we have to pass null.
var afterNextSibling = (afterNode && afterNode.nextSibling) || null;
forEach(element, function(node) {
parentNode.insertBefore(node, afterNextSibling);
});
if (after) {
after.after(element);
} else {
if (!parent || !parent[0]) {
parent = after.parent();
}
parent.append(element);
}
done && $timeout(done, 0, false);
},

Expand Down
25 changes: 25 additions & 0 deletions test/ng/directive/ngIncludeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,31 @@ describe('ngInclude', function() {
}));


it('should exec scripts when jQuery is included', inject(function($compile, $rootScope, $httpBackend) {
if (!jQuery) {
return;
}

element = $compile('<div><span ng-include="includeUrl"></span></div>')($rootScope);

// the element needs to be appended for the script to run
element.appendTo(document.body);
window._ngIncludeCausesScriptToRun = false;
$httpBackend.expect('GET', 'url1').respond('<script>window._ngIncludeCausesScriptToRun = true;</script>');
$rootScope.includeUrl = 'url1';
$rootScope.$digest();
$httpBackend.flush();

expect(window._ngIncludeCausesScriptToRun).toBe(true);

// IE8 doesn't like deleting properties of window
window._ngIncludeCausesScriptToRun = undefined;
try {
delete window._ngIncludeCausesScriptToRun;
} catch (e) {}
}));


describe('autoscroll', function() {
var autoScrollSpy;

Expand Down

0 comments on commit c47abd0

Please sign in to comment.