title: How to reset input field on Escape to previous value
body: <p>Whats the proper way to set an input field to its previous value, when escape key is pressed? </p>
  
  <p>I found this directive:</p>
  
  <pre><code>.directive('resetWithEsc', function() {
      return {
          restrict: 'A',
          require: '?ngModel',
          link: function(scope, element, attrs, controller) {
              element.on('keydown', function(ev) {
                  if (ev.keyCode != 27) return;
  
                  scope.$apply(function() {
                      controller.$setViewValue("");
                      controller.$render();
                  });
              });
          }
      };
  })
  </code></pre>
  
  <p>but it says <code>TypeError: Cannot read property '$setViewValue' of null</code></p>
  
  <p>I also tried to store the prev. value in $scope.temp and used directive to detect ESC press:</p>
  
  <pre><code>.directive('escKey', function () {
      return function (scope, element, attrs) {
          element.bind('keyup', function (event) {
              console.log("UP");
              if(event.which === 27) { // 27 = esc key
                  console.log("ESC");
                  scope.$apply(function (){
                      scope.$eval(attrs.escKey);
                  });
                  event.preventDefault();
              }
          });
      };
  })
  </code></pre>
  
  <p>then I used it like this:</p>
  
  <pre><code>&lt;input data-ng-focus="temp = mymodel.value"
      ng-model-options="{updateOn: 'blur'}" esc-key="mymodel.value = temp" 
      type="text" data-ng-model="mymodel.value"
  /&gt;
  </code></pre>
  
  <p>It detects proper the escape key, and if I set <code>esc-key="mymodel.value = 'TEST'"</code> it also sets the input field to <code>'TEST'</code>, but with the variable it's not working.</p>
  
  <p>So whats the best option to do so? I need it dynamic for use in repeat loops.</p>