Skip to content

Commit

Permalink
fix(1.x): inject $scope into activate hook
Browse files Browse the repository at this point in the history
  • Loading branch information
btford committed Mar 28, 2015
1 parent 145697e commit 2136ca8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/router-directive.es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function ngViewportDirective($animate, $injector, $q, $router) {
return;
}

newScope = scope.$new();
instruction.locals.$scope = newScope = scope.$new();
myCtrl.$$router = instruction.router;
myCtrl.$$template = instruction.template;
var componentName = instruction.component;
Expand Down
19 changes: 19 additions & 0 deletions test/router-viewport.es5.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,25 @@ describe('ngViewport', function () {
}));


it('should inject $scope into the activate hook of a controller', function () {
var spy = jasmine.createSpy('activate');
spy.$inject = ['$scope'];
registerComponent('user', '', {
activate: spy
});

$router.config([
{ path: '/user/:name', component: 'user' }
]);
compile('<div ng-viewport></div>');

$router.navigate('/user/brian');
$rootScope.$digest();

expect(spy.calls.first().args[0].$root).toEqual($rootScope);
});


it('should run the deactivate hook of controllers', function () {
var spy = jasmine.createSpy('deactivate');
registerComponent('deactivate', '', {
Expand Down

0 comments on commit 2136ca8

Please sign in to comment.