feat(router): Added method to get current instruction

This method delegates to the root router to get the current complete instruction.
This commit is contained in:
Brandon Roberts
2016-02-18 09:25:03 -06:00
committed by Vikram Subramanian
parent 15e16148f4
commit 6dce4f49c2
4 changed files with 81 additions and 16 deletions

View File

@ -246,7 +246,7 @@
var paramsObj = {};
$rootScope.$on('$routeChangeSuccess', function () {
var newParams = $rootRouter._currentInstruction && $rootRouter._currentInstruction.component.params;
var newParams = $rootRouter.currentInstruction && $rootRouter.currentInstruction.component.params;
angular.forEach(paramsObj, function (val, name) {
delete paramsObj[name];

View File

@ -120,6 +120,46 @@ describe('router', function () {
expect($routerOnActivate).toHaveBeenCalled();
}));
it('should provide the current instruction', inject(function($location, $q) {
registerComponent('homeCmp', {
template: 'Home ({{homeCmp.isAdmin}})'
});
registerComponent('app', {
template: '<div ng-outlet></div>',
$routeConfig: [
{ path: '/', component: 'homeCmp', name: 'Home' }
]
});
compile('<app></app>');
$location.path('/');
$rootScope.$digest();
var instruction = $rootRouter.generate(['/Home']);
expect($rootRouter.currentInstruction).toEqual(instruction);
}));
it('should provide the root level router', inject(function($location, $q) {
registerComponent('homeCmp', {
template: 'Home ({{homeCmp.isAdmin}})',
bindings: {
$router: '<'
}
});
registerComponent('app', {
template: '<div ng-outlet></div>',
$routeConfig: [
{ path: '/', component: 'homeCmp', name: 'Home' }
]
});
compile('<app></app>');
$location.path('/');
$rootScope.$digest();
var homeElement = elt.find('home-cmp');
expect(homeElement.isolateScope().$ctrl.$router.root).toEqual($rootRouter);
}));
function registerDirective(name, options) {
function factory() {