feat(angular1_router): Add ng-link-active class to active ng-link
Closes #6882
This commit is contained in:
parent
81beb1c788
commit
11e8aa26f6
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 () {};
|
||||
|
|
Loading…
Reference in New Issue