diff --git a/modules/angular1_router/src/ng_outlet.ts b/modules/angular1_router/src/ng_outlet.ts index 7c450bb40d..62bfe20635 100644 --- a/modules/angular1_router/src/ng_outlet.ts +++ b/modules/angular1_router/src/ng_outlet.ts @@ -156,10 +156,11 @@ function ngOutletDirective($animate, $q: ng.IQService, $router) { this.controller.$$routeParams = instruction.params; this.controller.$$template = - '<' + dashCase(componentName) + '>' + dashCase(componentName) + '>'; + '<' + dashCase(componentName) + ' router="$$router">' + dashCase(componentName) + '>'; this.controller.$$router = this.router.childRouter(instruction.componentType); let newScope = scope.$new(); + newScope.$$router = this.controller.$$router; let clone = $transclude(newScope, clone => { $animate.enter(clone, null, this.currentElement || element); diff --git a/modules/angular1_router/test/integration/router_spec.js b/modules/angular1_router/test/integration/router_spec.js index c302c21cea..bea802f366 100644 --- a/modules/angular1_router/test/integration/router_spec.js +++ b/modules/angular1_router/test/integration/router_spec.js @@ -44,36 +44,84 @@ describe('router', function () { expect(elt.text()).toBe('Home'); })); - function registerComponent(name, options) { - var controller = options.controller || function () {}; - ['$onActivate', '$onDeactivate', '$onReuse', '$canReuse', '$canDeactivate'].forEach(function (hookName) { - if (options[hookName]) { - controller.prototype[hookName] = options[hookName]; - } + it('should bind the component to the current router', inject(function($location) { + var router; + registerComponent('homeCmp', { + bindings: { router: '=' }, + controller: function($scope, $element) { + this.$routerOnActivate = function() { + router = this.router; + }; + }, + template: 'Home' }); + registerComponent('app', { + template: '
', + $routeConfig: [ + { path: '/', component: 'homeCmp' } + ] + }); + + compile('