feat(angular1_router): Add ng-link-active class to active ng-link
Closes #6882
This commit is contained in:
@ -257,6 +257,16 @@ function ngLinkDirective($rootRouter, $parse) {
|
|||||||
|
|
||||||
function getLink(params) {
|
function getLink(params) {
|
||||||
instruction = router.generate(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);
|
return './' + angular.stringifyInstruction(instruction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
modules/angular1_router/test/ng_link_spec.js
vendored
14
modules/angular1_router/test/ng_link_spec.js
vendored
@ -135,6 +135,20 @@ describe('ngLink', function () {
|
|||||||
}).not.toThrow();
|
}).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) {
|
function registerComponent(name, template, config) {
|
||||||
var controller = function () {};
|
var controller = function () {};
|
||||||
|
Reference in New Issue
Block a user