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

add template url argument to $includeContentRequested event #8454

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ng/directive/ngInclude.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,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 Source URL.
*/


Expand Down Expand Up @@ -234,7 +237,7 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$animate'
currentScope = newScope;
currentElement = clone;

currentScope.$emit('$includeContentLoaded');
currentScope.$emit('$includeContentLoaded', src);
scope.$eval(onloadExp);
}).error(function() {
if (thisChangeId === changeCounter) {
Expand Down
11 changes: 11 additions & 0 deletions test/ng/directive/ngIncludeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,17 @@ describe('ngInclude', function() {
} catch (e) {}
}));

it('should fire $includeContentLoaded with the template url as the second parameter', inject(function($rootScope, $compile, $templateCache) {
var called = 0;
$templateCache.put('/some/template.html', [200, '', {}]);
$rootScope.$on('$includeContentLoaded', function(event, src) {
expect(src).toBe('/some/template.html');
called++;
});
element = $compile('<div><ng:include src="\'/some/template.html\'"></ng:include></div>')($rootScope);
$rootScope.$digest();
expect(called).toBe(1);
}));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is cleaner to use jasmine spies for this kind of test. Something like this:

it('should fire $includeContentLoaded with the template url as the second parameter', inject(function($rootScope, $compile, $templateCache) {
    var handlerSpy = jasmine.createSpy('handler');
    $templateCache.put('/some/template.html', [200, '', {}]);
    $rootScope.$on('$includeContentLoaded', handlerSpy);
    element = $compile('<div><ng:include src="\'/some/template.html\'"></ng:include></div>')($rootScope);
    $rootScope.$digest();
    expect(handlerSpy).toHaveBeenCalledWith(jasmine.any(Object), '/some/template.html');
  }));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, check it out!


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