feat(angular1_router): Add ng-link-active class to active ng-link

Closes #6882
This commit is contained in:
Brandon Roberts 2016-02-03 21:50:51 -06:00 committed by Brandon
parent 81beb1c788
commit 11e8aa26f6
2 changed files with 24 additions and 0 deletions

View File

@ -257,6 +257,16 @@ function ngLinkDirective($rootRouter, $parse) {
function getLink(params) {
instruction = router.generate(params);
scope.$watch(function() { return router.isRouteActive(instruction); },
function(active) {
if (active) {
element.addClass('ng-link-active');
} else {
element.removeClass('ng-link-active');
}
});
return './' + angular.stringifyInstruction(instruction);
}

View File

@ -135,6 +135,20 @@ describe('ngLink', function () {
}).not.toThrow();
});
it('should add an ng-link-active class on the current link', inject(function ($rootRouter) {
$rootRouter.config([
{ path: '/', component: 'oneCmp', name: 'One' }
]);
compile('<a ng-link="[\'/One\']">one</a> | <div ng-outlet></div>');
$rootScope.$digest();
$rootRouter.navigateByUrl('/');
$rootScope.$digest();
expect(elt.find('a').attr('class')).toBe('ng-link-active');
}));
function registerComponent(name, template, config) {
var controller = function () {};