Rectangle 27 26

The accepted answer does not work for IE 10/11. Here is a solution based on another question that does:

.directive('escKey', function () {
  return function (scope, element, attrs) {
    element.bind('keydown keypress', function (event) {
      if(event.which === 27) { // 27 = esc key
        scope.$apply(function (){
          scope.$eval(attrs.escKey);
        });

        event.preventDefault();
      }
    });
  };
})
<input ... ng-model="filter.abc" esc-key="resetFilter()" >
$scope.resetFilter = function() {
  $scope.filter.abc = null;
};

eval is evil, you can bind method to directive in a proper way using &, more info here.

I loved this so much that, after using it on a bunch of stuff I just went ahead and make a repo for it. github.com/deltreey/angular-esc-key If you would prefer, I will transfer it to you, but I'm happy to maintain it.

Feel free to do so I don't mind. When I have time I'll also try to improve the solution with the proposal by @icl7126 and send a pull request. Also if you have improvements feel free to update my answer.

angularjs - Clear input text field in Angular / AngularUI with ESC key...

input angularjs clear angular-ui
Rectangle 27 18

The OP's script doesn't work in IE 7. With help from SO, here's a script that does:

exec_body_scripts: function(body_el) {
  // Finds and executes scripts in a newly added element's body.
  // Needed since innerHTML does not run scripts.
  //
  // Argument body_el is an element in the dom.

  function nodeName(elem, name) {
    return elem.nodeName && elem.nodeName.toUpperCase() ===
              name.toUpperCase();
  };

  function evalScript(elem) {
    var data = (elem.text || elem.textContent || elem.innerHTML || "" ),
        head = document.getElementsByTagName("head")[0] ||
                  document.documentElement,
        script = document.createElement("script");

    script.type = "text/javascript";
    try {
      // doesn't work on ie...
      script.appendChild(document.createTextNode(data));      
    } catch(e) {
      // IE has funky script nodes
      script.text = data;
    }

    head.insertBefore(script, head.firstChild);
    head.removeChild(script);
  };

  // main section of function
  var scripts = [],
      script,
      children_nodes = body_el.childNodes,
      child,
      i;

  for (i = 0; children_nodes[i]; i++) {
    child = children_nodes[i];
    if (nodeName(child, "script" ) &&
      (!child.type || child.type.toLowerCase() === "text/javascript")) {
          scripts.push(child);
      }
  }

  for (i = 0; scripts[i]; i++) {
    script = scripts[i];
    if (script.parentNode) {script.parentNode.removeChild(script);}
    evalScript(scripts[i]);
  }
};
$(parent).html(code)
if (nodeName(child, "script" ) &&   (!child.type || child.type.toLowerCase() === "text/javascript")) {       scripts.push(child);   } else {     exec_body_scripts(child);   }

Note that the above code doesn't execute scripts that load via src. The above script can be changed to check elem.src and conditionally set the src property of the created script element instead of setting its text content.

javascript - Executing