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

Commit af0eaa3

Browse files
mlarcherpetebacondarwin
authored andcommitted
feat(ngInclude): $includeContentRequested event
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.
1 parent a348e90 commit af0eaa3

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/ng/directive/ngInclude.js

+11
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@
114114
*/
115115

116116

117+
/**
118+
* @ngdoc event
119+
* @name ng.directive:ngInclude#$includeContentRequested
120+
* @eventOf ng.directive:ngInclude
121+
* @eventType emit on the scope ngInclude was declared in
122+
* @description
123+
* Emitted every time the ngInclude content is requested.
124+
*/
125+
126+
117127
/**
118128
* @ngdoc event
119129
* @name ng.directive:ngInclude#$includeContentLoaded
@@ -170,6 +180,7 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'
170180
}).error(function() {
171181
if (thisChangeId === changeCounter) clearContent();
172182
});
183+
scope.$emit('$includeContentRequested');
173184
} else {
174185
clearContent();
175186
}

test/ng/directive/ngIncludeSpec.js

+16
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ describe('ngInclude', function() {
5959
expect(element.text()).toEqual('');
6060
}));
6161

62+
it('should fire $includeContentRequested event on scope after making the xhr call', inject(
63+
function ($rootScope, $compile, $httpBackend) {
64+
var contentRequestedSpy = jasmine.createSpy('content requested').andCallFake(function (event) {
65+
expect(event.targetScope).toBe($rootScope);
66+
});
67+
68+
$httpBackend.whenGET('url').respond('my partial');
69+
$rootScope.$on('$includeContentRequested', contentRequestedSpy);
70+
71+
element = $compile('<ng:include src="\'url\'"></ng:include>')($rootScope);
72+
$rootScope.$digest();
73+
74+
expect(contentRequestedSpy).toHaveBeenCalledOnce();
75+
76+
$httpBackend.flush();
77+
}));
6278

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

0 commit comments

Comments
 (0)