fix(angular1_router): ngLink should not throw an error if routeParams are undefined (#8460)

If routeParams are undefined, no href attribute should be rendered. This matches the behaviour of ngHref.
This commit is contained in:
David Reher 2016-05-20 18:48:03 +02:00 committed by Miško Hevery
parent 3857c8226e
commit 9b1b5b393d
2 changed files with 16 additions and 0 deletions

View File

@ -213,6 +213,10 @@ function ngLinkDirective($rootRouter, $parse) {
let link = attrs.ngLink || '';
function getLink(params) {
if (!params) {
return;
}
navigationInstruction = router.generate(params);
scope.$watch(function() { return router.isRouteActive(navigationInstruction); },

View File

@ -140,6 +140,18 @@ describe('ngLink', function () {
navigateTo('/');
expect(elt.find('a').attr('class')).toBe('ng-link-active');
});
it('should not add a href if link attributes are undefined', function () {
setup({baseHref: baseHref, html5Mode: html5Mode, hashPrefix: hashPrefix});
configureRouter([
{ path: '/a', component: 'oneCmp' },
{ path: '/b', component: 'twoCmp', name: 'Two' }
]);
var elt = compile('<a ng-link="something.undefined">link</a> | outer { <div ng-outlet></div> }');
navigateTo('/a');
expect(elt.find('a').hasAttr('href')).toBeFalsy();
});
}
function registerComponent(name, template, controller) {