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

Commit 2136ca8

Browse files
committed
fix(1.x): inject $scope into activate hook
Closes #192
1 parent 145697e commit 2136ca8

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/router-directive.es5.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function ngViewportDirective($animate, $injector, $q, $router) {
177177
return;
178178
}
179179

180-
newScope = scope.$new();
180+
instruction.locals.$scope = newScope = scope.$new();
181181
myCtrl.$$router = instruction.router;
182182
myCtrl.$$template = instruction.template;
183183
var componentName = instruction.component;

test/router-viewport.es5.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,25 @@ describe('ngViewport', function () {
244244
}));
245245

246246

247+
it('should inject $scope into the activate hook of a controller', function () {
248+
var spy = jasmine.createSpy('activate');
249+
spy.$inject = ['$scope'];
250+
registerComponent('user', '', {
251+
activate: spy
252+
});
253+
254+
$router.config([
255+
{ path: '/user/:name', component: 'user' }
256+
]);
257+
compile('<div ng-viewport></div>');
258+
259+
$router.navigate('/user/brian');
260+
$rootScope.$digest();
261+
262+
expect(spy.calls.first().args[0].$root).toEqual($rootScope);
263+
});
264+
265+
247266
it('should run the deactivate hook of controllers', function () {
248267
var spy = jasmine.createSpy('deactivate');
249268
registerComponent('deactivate', '', {

0 commit comments

Comments
 (0)