diff options
| -rw-r--r-- | src/ng/directive/ngInclude.js | 11 | ||||
| -rw-r--r-- | test/ng/directive/ngIncludeSpec.js | 16 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/ng/directive/ngInclude.js b/src/ng/directive/ngInclude.js index 45800e75..730c7bdf 100644 --- a/src/ng/directive/ngInclude.js +++ b/src/ng/directive/ngInclude.js @@ -116,6 +116,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 * @eventOf ng.directive:ngInclude * @eventType emit on the current ngInclude scope @@ -170,6 +180,7 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile' }).error(function() { if (thisChangeId === changeCounter) clearContent(); }); + scope.$emit('$includeContentRequested'); } else { clearContent(); } diff --git a/test/ng/directive/ngIncludeSpec.js b/test/ng/directive/ngIncludeSpec.js index a990a840..1ce55bb4 100644 --- a/test/ng/directive/ngIncludeSpec.js +++ b/test/ng/directive/ngIncludeSpec.js @@ -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) { |
