Files
openfoodnetwork/app/assets/javascripts/darkswarm/directives/disable_dynamically.js.coffee
Matt-Yorkley 15b6b1271a Remove event handlers in Angular directives on the $destroy event
This is a common source of memory leaks!
2021-08-03 16:20:19 +01:00

15 lines
408 B
CoffeeScript

# Allows disabling of link buttons via disabled attribute.
# This is normally ignored, ie the link appears disabled but is still clickable.
angular.module('Darkswarm').directive "disableDynamically", ->
restrict: 'A'
link: (scope, element, attrs) ->
element.on 'click', (e) ->
if attrs.disabled
e.preventDefault()
return
scope.$on "$destroy", ->
element.off("click")