Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
94
rated 0 times [  101] [ 7]  / answers: 1 / hits: 58776  / 12 Years ago, sun, january 27, 2013, 12:00:00

I am trying to stopPropagation to prevent a Twitter Bootstrap navbar dropdown from closing when an element (link) inside an li is clicked. Using this method seems to be the common solution.



In Angular, seems like a directive is the place to do this? So I have:



// do not close dropdown on click
directives.directive('stopPropagation', function () {
return {
link:function (elm) {
$(elm).click(function (event) {
event.stopPropagation();
});
}
};
});


... but the method does not belong to element:



TypeError: Object [object Object] has no method 'stopPropagation'


I tie in the directive with



<li ng-repeat=foo in bar>
<div>
{{foo.text}}<a stop-propagation ng-click=doThing($index)>clickme</a>
</div>
</li>


Any suggestions?


More From » jquery

 Answers
10

Currently some directives (i.e. ng:click) stops event propagation. This prevents interoperability with other frameworks that rely on capturing such events. - link



... and was able to fix without a directive, and simply doing:



<a ng-click=doThing($index); $event.stopPropagation();>x</a>

[#80600] Friday, January 25, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckinleykeyshawnb

Total Points: 281
Total Questions: 99
Total Answers: 111

Location: Saudi Arabia
Member since Sat, Aug 20, 2022
2 Years ago
;