Feature request: allow ngEvents to opt out of $apply #9280
Description
Right now, assigning ngEvent directives such as ngClick or ngMouseenter on an element causes it to always call apply when those events are triggered. This can be a huge performance issue if you have ngMousemove on a large element in a large application. It'll trigger $apply continuously which makes it almost unusable. There are also cases where a developer wants to listen to some events (and only trigger certain expressions) only under certain conditions instead of all the time.
I suggest a function that can opt out of $apply which could be useful for developers who want to trigger $apply only when it's needed.
This could come in the form of a local function such as $shouldApply
, where the user can call $shouldApply(false)
in their expression. Or it can simply follow the preventDefault
convention by having a $preventApply()
function. I don't think it should use the event.preventDefault
to determine not to $apply though, since that maybe used for other purposes by the developer.