       key = scope.$eval(key)
 
     if attrs.ycKeyCommand?
-      cmd = safeApply scope, () ->
+      cmd = () -> safeApply(scope, () ->
         scope.$eval(attrs.ycKeyCommand)
+      )
     else if (element.prop('tagName')?.match /a/i)
       cmd = () ->
         if(element.prop('href')?.length > 0)

  we'll try to either follow the link or else trigger the click event.
  ###
  link: (scope, element, attrs) ->


    ## This is hacky, and prevents ":" from being used as an actual key binding.
    delim = attrs.ycKey.indexOf(":")


    glossary: glossary

).directive("ycKey", ($log, $parse, $window, $rootScope, $location, keyCommands) ->
  safeApply = (scope, fn) ->
    if(scope.$$phase)
      fn()
    else
