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:
parent
3857c8226e
commit
9b1b5b393d
|
@ -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); },
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue