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

htmlAnchorDirective click event stop bubbling... #1651

Closed
lancon13 opened this issue Dec 5, 2012 · 8 comments
Closed

htmlAnchorDirective click event stop bubbling... #1651

lancon13 opened this issue Dec 5, 2012 · 8 comments

Comments

@lancon13
Copy link

lancon13 commented Dec 5, 2012

Hi, I just upgraded my angular.js from 1.0.2 to 1.0.3, and having an issue with this fix after the upgrade.

Since my app has some elements listen to event delegation from JQuery.

1.0.2
http://plnkr.co/edit/iSem7DYn3b3ERgpD2LTu?p=preview

1.0.3
http://plnkr.co/edit/1SR7IAwrxDmHcE553ylI?p=preview

However, it doesn't work anymore, as the "a" element (htmlAnchorDirective) "click" event now stop bubbling up...

I just looking at the JQuery Doc, it seems "event.preventDefault()" and "return false" should be doing different things.

http://api.jquery.com/bind/

Example: Cancel a default action and prevent it from bubbling up by returning false:
$("form").bind("submit", function() { return false; })

Example: Cancel only the default action by using the .preventDefault() method.
$("form").bind("submit", function(event) { event.preventDefault(); });

Sorry for my bad english...

@Letsan
Copy link

Letsan commented Dec 14, 2012

I experienced the same problem with some Bootstrap dropdowns not closing when clicked and no href was specified for the list items.

Removing the "return false" fixes it.

@marcalj
Copy link

marcalj commented Dec 14, 2012

I found another error (I think), the ng-click works on an ng-disabled anchor:

<a ng-disabled="true" ng-click="miau = 2">miau: {{ miau }}</a>

I should open a new issue? Thanks!

@Letsan
Copy link

Letsan commented Dec 14, 2012

Don't think so, maybe this answers your question:

http://onehungrymind.com/quick-note-ng-disabled-and-anchor-tags-oh-noes/

Does it behave the same way when using Angular 1.0.2 ?

@marcalj
Copy link

marcalj commented Dec 15, 2012

@Letsan jajajaja thanks. This was funny :p

I've begin using AngularJS since yesterday with 1.0.3, I suppose will behave the same.

@Letsan
Copy link

Letsan commented Dec 15, 2012

Actually it does behave the same in 1.0.2 this behaviour seems expected.
http://jsfiddle.net/uUtwx/

@davispw
Copy link

davispw commented Dec 18, 2012

This is caused by c81d817. Quick fix: comment out "return false".

IgorMinar added a commit that referenced this issue Jan 8, 2013
This reverts commit c81d817.

This commit causes several issues (#1651, #1674, #1662) and doesn't even
contain a test that proves that anything on Opera got actually fixed.

If the original Opera resurfaces, we'll fix it properly.
IgorMinar added a commit that referenced this issue Jan 8, 2013
This reverts commit c81d817.

This commit causes several issues (#1651, #1674, #1662) and doesn't even
contain a test that proves that anything on Opera got actually fixed.

If the original Opera resurfaces, we'll fix it properly.
@IgorMinar
Copy link
Contributor

fixed by 14948cf

jamessharp pushed a commit to jamessharp/angular.js that referenced this issue Jan 18, 2013
This reverts commit c81d817.

This commit causes several issues (angular#1651, angular#1674, angular#1662) and doesn't even
contain a test that proves that anything on Opera got actually fixed.

If the original Opera resurfaces, we'll fix it properly.
@gouravmakhija18
Copy link

May be below code will help you

if(element.prop("tagName") == 'A'){
if (!element.attr('href')) {
event.preventDefault();
}
}

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

No branches or pull requests

6 participants