title: Get current focus dynamically with angular.element function
body: <p>I'm trying to get the current input focus dinamically with angular and typescript.
  I'm using the <em>angular.element([selector]).focus(handler)</em> function but it does not trigger when i click on an input.</p>
  
  <p>This is my code:</p>
  
  <pre><code>class TemplateController {
      lastFocused: HTMLInputElement;
  
      static $inject = ['$scope'];
      constructor(private $scope: ng.IScope) {
  
          angular.element("input[type='text']").focus((): void =&gt; {
              this.lastFocused = document.activeElement as HTMLInputElement;
              console.log("FOCUSED");
          });
      }
  }
  
  angular
      .module("app")
      .controller("[...]templateController", TemplateController);
  }
  </code></pre>
  
  <p>And this is my html (input snippet):</p>
  
  <pre><code>...
  
  &lt;input class="form-control" type="text" id="title" name="title" size="30" ng-maxlength="1000" required /&gt;
  
  ...
  </code></pre>
  
  <p>What I'm doing wrong?</p>
  
  <p>Thanks in advance :)</p>
  
  <p><strong>EDIT: Solved</strong></p>
  
  <p>I was able to solve this problem by using <em>ng-focus</em> attribute on the input element:</p>
  
  <pre><code>&lt;input class="form-control" type="text" id="title" name="title" size="30" ng-maxlength="1000" required ng-focus="templateCtrl.setFocusedElement()" /&gt;
  </code></pre>
  
  <p>and inside the controller:</p>
  
  <pre><code>setFocusedElement(): void {
      this.$scope.lastFocused = document.activeElement;
  }
  </code></pre>
  
  <p>This works fine for me :)</p>