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

Commit

Permalink
feat(ngInclude): $includeContentRequested event
Browse files Browse the repository at this point in the history
Adding a $includeContentRequested event in order to better keep track of
how many includes are sent and be able to compare it with how many have
finished.
  • Loading branch information
mlarcher authored and petebacondarwin committed May 3, 2013
1 parent a348e90 commit af0eaa3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ng/directive/ngInclude.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@
*/


/**
* @ngdoc event
* @name ng.directive:ngInclude#$includeContentRequested
* @eventOf ng.directive:ngInclude
* @eventType emit on the scope ngInclude was declared in
* @description
* Emitted every time the ngInclude content is requested.
*/


/**
* @ngdoc event
* @name ng.directive:ngInclude#$includeContentLoaded
Expand Down Expand Up @@ -170,6 +180,7 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'
}).error(function() {
if (thisChangeId === changeCounter) clearContent();
});
scope.$emit('$includeContentRequested');
} else {
clearContent();
}
Expand Down
16 changes: 16 additions & 0 deletions test/ng/directive/ngIncludeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ describe('ngInclude', function() {
expect(element.text()).toEqual('');
}));

it('should fire $includeContentRequested event on scope after making the xhr call', inject(
function ($rootScope, $compile, $httpBackend) {
var contentRequestedSpy = jasmine.createSpy('content requested').andCallFake(function (event) {
expect(event.targetScope).toBe($rootScope);
});

$httpBackend.whenGET('url').respond('my partial');
$rootScope.$on('$includeContentRequested', contentRequestedSpy);

element = $compile('<ng:include src="\'url\'"></ng:include>')($rootScope);
$rootScope.$digest();

expect(contentRequestedSpy).toHaveBeenCalledOnce();

$httpBackend.flush();
}));

it('should fire $includeContentLoaded event on child scope after linking the content', inject(
function($rootScope, $compile, $templateCache) {
Expand Down

0 comments on commit af0eaa3

Please sign in to comment.