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

Commit fd2d6c0

Browse files
stephenbunchpetebacondarwin
authored andcommitted
feat(ngInclude): add template url parameter to events
The 'src` (i.e. the url of the template to load) is now provided to the `$includeContentRequested`, `$includeContentLoaded` and `$includeContentError` events. Closes #8453 Closes #8454
1 parent cfdd161 commit fd2d6c0

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

Diff for: src/ng/directive/ngInclude.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@
150150
* @eventType emit on the scope ngInclude was declared in
151151
* @description
152152
* Emitted every time the ngInclude content is requested.
153+
*
154+
* @param {Object} angularEvent Synthetic event object.
155+
* @param {String} src URL of content to load.
153156
*/
154157

155158

@@ -159,6 +162,9 @@
159162
* @eventType emit on the current ngInclude scope
160163
* @description
161164
* Emitted every time the ngInclude content is reloaded.
165+
*
166+
* @param {Object} angularEvent Synthetic event object.
167+
* @param {String} src URL of content to load.
162168
*/
163169

164170

@@ -168,6 +174,9 @@
168174
* @eventType emit on the scope ngInclude was declared in
169175
* @description
170176
* Emitted when a template HTTP request yields an erronous response (status < 200 || status > 299)
177+
*
178+
* @param {Object} angularEvent Synthetic event object.
179+
* @param {String} src URL of content to load.
171180
*/
172181
var ngIncludeDirective = ['$templateRequest', '$anchorScroll', '$animate', '$sce',
173182
function($templateRequest, $anchorScroll, $animate, $sce) {
@@ -236,15 +245,15 @@ var ngIncludeDirective = ['$templateRequest', '$anchorScroll', '$animate', '$sce
236245
currentScope = newScope;
237246
currentElement = clone;
238247

239-
currentScope.$emit('$includeContentLoaded');
248+
currentScope.$emit('$includeContentLoaded', src);
240249
scope.$eval(onloadExp);
241250
}, function() {
242251
if (thisChangeId === changeCounter) {
243252
cleanupLastIncludeContent();
244-
scope.$emit('$includeContentError');
253+
scope.$emit('$includeContentError', src);
245254
}
246255
});
247-
scope.$emit('$includeContentRequested');
256+
scope.$emit('$includeContentRequested', src);
248257
} else {
249258
cleanupLastIncludeContent();
250259
ctrl.template = null;

Diff for: test/ng/directive/ngIncludeSpec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ describe('ngInclude', function() {
121121
element = $compile('<div><div><ng:include src="\'url\'"></ng:include></div></div>')($rootScope);
122122
$rootScope.$digest();
123123

124-
expect(contentRequestedSpy).toHaveBeenCalledOnce();
124+
expect(contentRequestedSpy).toHaveBeenCalledOnceWith(jasmine.any(Object), 'url');
125125

126126
$httpBackend.flush();
127127
}));
@@ -139,7 +139,7 @@ describe('ngInclude', function() {
139139
element = $compile('<div><div><ng:include src="\'url\'"></ng:include></div></div>')($rootScope);
140140
$rootScope.$digest();
141141

142-
expect(contentLoadedSpy).toHaveBeenCalledOnce();
142+
expect(contentLoadedSpy).toHaveBeenCalledOnceWith(jasmine.any(Object), 'url');
143143
}));
144144

145145

@@ -161,7 +161,7 @@ describe('ngInclude', function() {
161161
$httpBackend.flush();
162162

163163
expect(contentLoadedSpy).not.toHaveBeenCalled();
164-
expect(contentErrorSpy).toHaveBeenCalledOnce();
164+
expect(contentErrorSpy).toHaveBeenCalledOnceWith(jasmine.any(Object), 'tpl.html');
165165
expect(element.children('div').contents().length).toBe(0);
166166
}));
167167

0 commit comments

Comments
 (0)