Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

ng-href in <a> tag ignores empty value "" #2755

Closed
liokm opened this issue May 23, 2013 · 10 comments
Closed

ng-href in <a> tag ignores empty value "" #2755

liokm opened this issue May 23, 2013 · 10 comments

Comments

@liokm
Copy link

liokm commented May 23, 2013

According to b6e4a71, currently ng-href and ng-src ignores false values when setting attributes. However, since an empty value is valid for href of <a> tag, we could safely set it. Is it right?

@btford btford closed this as completed Aug 24, 2013
@btford
Copy link
Contributor

btford commented Aug 24, 2013

As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.

Please try the newest versions of Angular (1.0.8 and 1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.

Thanks!

@frapontillo
Copy link
Contributor

This issue persists in 1.2.0-rc.1, and it's pretty annoying for a elements, as an empty evaluated ng-href is not set to the href attribute. How can someone delete a link previously bound to another model?

@vijaychandramadrone
Copy link

Is this ticket closed? While making ng-href to empty/blank href attribute still contains value.
If i make ng-href="http://google.com" to ng-href="" href attribute still contains the value like href="http:/g". Below is the screen shot of browser console.

image

@caitp
Copy link
Contributor

caitp commented Apr 3, 2014

post a reproduction, please.

@shahata
Copy link
Contributor

shahata commented Apr 3, 2014

Tried it out and it is indeed the case: http://plnkr.co/edit/vPsYsF60GO3CKQ28jzmS?p=preview
Click on link opens google, but click on 'reset' and then click on link still take you to google.
If you confirm that this is indeed something that should be fixed, I'll be happy to take this PR myself.

@caitp
Copy link
Contributor

caitp commented Apr 3, 2014

ah, I see the issue, https://github.com/angular/angular.js/blob/master/src/ng/directive/booleanAttrs.js#L383-L384

attr.$observe(normalized, function(value) {
  if (!value)
    return;
  // ...  

It might break tests to change that, though. Anyways yeah, feel free to send a PR

@caitp
Copy link
Contributor

caitp commented Apr 3, 2014

The reason given for that snippet is this b6e4a71

So I think we can probably satisfy those requirements without hurting other peoples apps

@vijaychandramadrone
Copy link

Here is the PR
http://jsfiddle.net/cTE7Y/8/

@shahata : The fix which u gave seems good but leads me to add unwanted code.

@aeharding
Copy link

Just fyi, this caused an issue in my app: we use href='' for tabbing (tabindex='0' is annoying as it adds styles when normal clicking with mouse, also no functionality when hit enter) along with ngHref if a string is specified for a url. If not though, the href='' is being removed...

Just a bit annoying. Should've been breaking

@aeharding
Copy link

A fix for those interested:
image
to
image

a bit more nasty. ngHref should not get rid of 'href' attribute when it didn't last change it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants