title: AngularJS: How to trigger function call when a form field gets focus
body: <p>I want my controller to perform some action when a user clicks in a form field (when the form field gets focus). How can I do this? See <a href="http://plnkr.co/edit/bQUKhn?p=preview" rel="nofollow">this plunker</a>.</p>
  
  <p>Here is my controller:
  angular.module('myApp', [])</p>
  
  <pre><code>.controller('AppCtrl', ['$scope',
    function($scope) {
      $scope.field1 = "Default text";
      $scope.focus = false;
      $scope.formFieldJustGotFocus = function() {
        $scope.focus = true; 
        // Do all the stuff I need to happen when the form has just gotten focus
      }
    }
  ]);
  </code></pre>
  
  <p>And here is the view:</p>
  
  <pre><code>&lt;body ng-app="myApp" ng-controller="AppCtrl"&gt;
    &lt;h3&gt;Testing&lt;/h3&gt;
    &lt;p&gt;I want to perform some action in the controller when a form field gets focus. How can I best achieve this?&lt;/p&gt;
    &lt;form name="myForm"&gt;
      &lt;input type="text" name="field1" ng-model="field1"&gt;
    &lt;/form&gt;
    &lt;p&gt;Form field has focus: {{focus}}&lt;/p&gt;
  &lt;/body&gt;
  </code></pre>