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
This commit is contained in:
Stephen Bunch
2014-08-19 08:00:17 -07:00
committed by Peter Bacon Darwin
parent cfdd16157e
commit fd2d6c02f9
2 changed files with 15 additions and 6 deletions

View File

@@ -150,6 +150,9 @@
* @eventType emit on the scope ngInclude was declared in
* @description
* Emitted every time the ngInclude content is requested.
*
* @param {Object} angularEvent Synthetic event object.
* @param {String} src URL of content to load.
*/
@@ -159,6 +162,9 @@
* @eventType emit on the current ngInclude scope
* @description
* Emitted every time the ngInclude content is reloaded.
*
* @param {Object} angularEvent Synthetic event object.
* @param {String} src URL of content to load.
*/
@@ -168,6 +174,9 @@
* @eventType emit on the scope ngInclude was declared in
* @description
* Emitted when a template HTTP request yields an erronous response (status < 200 || status > 299)
*
* @param {Object} angularEvent Synthetic event object.
* @param {String} src URL of content to load.
*/
var ngIncludeDirective = ['$templateRequest', '$anchorScroll', '$animate', '$sce',
function($templateRequest, $anchorScroll, $animate, $sce) {
@@ -236,15 +245,15 @@ var ngIncludeDirective = ['$templateRequest', '$anchorScroll', '$animate', '$sce
currentScope = newScope;
currentElement = clone;
currentScope.$emit('$includeContentLoaded');
currentScope.$emit('$includeContentLoaded', src);
scope.$eval(onloadExp);
}, function() {
if (thisChangeId === changeCounter) {
cleanupLastIncludeContent();
scope.$emit('$includeContentError');
scope.$emit('$includeContentError', src);
}
});
scope.$emit('$includeContentRequested');
scope.$emit('$includeContentRequested', src);
} else {
cleanupLastIncludeContent();
ctrl.template = null;

View File

@@ -121,7 +121,7 @@ describe('ngInclude', function() {
element = $compile('<div><div><ng:include src="\'url\'"></ng:include></div></div>')($rootScope);
$rootScope.$digest();
expect(contentRequestedSpy).toHaveBeenCalledOnce();
expect(contentRequestedSpy).toHaveBeenCalledOnceWith(jasmine.any(Object), 'url');
$httpBackend.flush();
}));
@@ -139,7 +139,7 @@ describe('ngInclude', function() {
element = $compile('<div><div><ng:include src="\'url\'"></ng:include></div></div>')($rootScope);
$rootScope.$digest();
expect(contentLoadedSpy).toHaveBeenCalledOnce();
expect(contentLoadedSpy).toHaveBeenCalledOnceWith(jasmine.any(Object), 'url');
}));
@@ -161,7 +161,7 @@ describe('ngInclude', function() {
$httpBackend.flush();
expect(contentLoadedSpy).not.toHaveBeenCalled();
expect(contentErrorSpy).toHaveBeenCalledOnce();
expect(contentErrorSpy).toHaveBeenCalledOnceWith(jasmine.any(Object), 'tpl.html');
expect(element.children('div').contents().length).toBe(0);
}));