From 90f87072e83234ae366cfeb3c281503c31dad738 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Thu, 14 Nov 2013 13:50:36 -0800 Subject: fix($compile): accessing controllers of transcluded directives from children Additional API (backwards compatible) - Injects `$transclude` (see directive controllers) as 5th argument to directive link functions. - `$transclude` takes an optional scope as first parameter that overrides the bound scope. Deprecations: - `transclude` parameter of directive compile functions (use the new parameter for link functions instead). Refactorings: - Don't use comment node to temporarily store controllers - `ngIf`, `ngRepeat`, ... now all use `$transclude` Closes #4935. --- test/ngRoute/directive/ngViewSpec.js | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test/ngRoute') diff --git a/test/ngRoute/directive/ngViewSpec.js b/test/ngRoute/directive/ngViewSpec.js index 1df19d6a..e96da022 100644 --- a/test/ngRoute/directive/ngViewSpec.js +++ b/test/ngRoute/directive/ngViewSpec.js @@ -514,6 +514,44 @@ describe('ngView', function() { }); }); +describe('ngView and transcludes', function() { + it('should allow access to directive controller from children when used in a replace template', function() { + var controller; + module('ngRoute'); + module(function($compileProvider, $routeProvider) { + $routeProvider.when('/view', {templateUrl: 'view.html'}); + var directive = $compileProvider.directive; + directive('template', function() { + return { + template: '
', + replace: true, + controller: function() { + this.flag = true; + } + }; + }); + + directive('test', function() { + return { + require: '^template', + link: function(scope, el, attr, ctrl) { + controller = ctrl; + } + }; + }); + }); + inject(function($compile, $rootScope, $httpBackend, $location) { + $httpBackend.expectGET('view.html').respond('
'); + var element = $compile('
')($rootScope); + $location.url('/view'); + $rootScope.$apply(); + $httpBackend.flush(); + expect(controller.flag).toBe(true); + dealoc(element); + }); + }); +}); + describe('ngView animations', function() { var body, element, $rootElement; -- cgit v1.2.3