prevent click on href

508 views
Skip to first unread message

Mike Brennan

unread,
Mar 18, 2013, 9:01:45 AM3/18/13
to ang...@googlegroups.com
I had previously used a directive to prevent clicking on a hyperlink:

something along the lines of:

directivesModule.directive('easPreventClick', function() {
        return function(scope, element, attrs) {
        $(element).click(function(event) {
            event.preventDefault();
        });
    }
});

http://jsfiddle.net/mjb14/EXWkt/14/

I'm not sure exactly when this stopped working, but this definitely worked at one point in time.  I am guessing this probably stopped working when an updated version of angular came out.

Is there another technique other people out there are using?  I need to keep the href around so that a user could right click on a link and open it in another window. 

Clint Checketts

unread,
Mar 18, 2013, 9:39:38 AM3/18/13
to ang...@googlegroups.com
You can use event.stopPropogation(). I believe this is because the inner event is bubbling up to trigger the href.  Also notice how JQuery isn't required on the element (I use element.bind).


        element.bind('click',function(event) {
$('#console').append("<br>prevent click");
            event.stopPropagation();
        });


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Mike Brennan

unread,
Mar 18, 2013, 10:00:24 AM3/18/13
to ang...@googlegroups.com
Worked great, thanks for the suggestion!


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/CW1vs-qPDrg/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages