AngularJS How to place focus on textbox when button click
<p>i have one textbox and few buttons and i want when user will click on any button then textbox will have focus. i tried this way but did not work <code>angular.element("#txtData").focus();</code></p>

<h2>my full code</h2>

<pre><code>&lt;div ng-app="myApp" ng-controller="myCtrl"&gt;
&lt;table border=2&gt;
&lt;tr&gt;
&lt;td colspan=5&gt;&lt;input type=text ng-model="Operantion" id="txtData" style="width:97%" ng-change="GetData(Operantion,'onChange')"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;input type=button value="+" ng-click="GetData('+','btnClick')"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=button value="-" ng-click="GetData('-','btnClick')"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=button value="x" ng-click="GetData('*','btnClick')"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=button value="/" ng-click="GetData('/','btnClick')"&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=button value="=" ng-click="GetData('=','btnClick')"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;

var app = angular.module('myApp', []);
app.controller('myCtrl', function ($scope) {
    $scope.GetData = function (arg1, evtType) {
        if (evtType === 'btnClick') {
            angular.element("#txtData").focus();
        }
    };
});
</code></pre>

<p>js fiddle <a href="https://jsfiddle.net/tridip/wzvq5ov8/" rel="nofollow noreferrer">https://jsfiddle.net/tridip/wzvq5ov8/</a></p>

<p>i found few same kind of post in this forum and saw people write many code to achieve this by custom directives. i am so new and that is why i do not understand their code. one similar post url here which i checked <a href="https://stackoverflow.com/a/15529412/728750">https://stackoverflow.com/a/15529412/728750</a></p>

<p>this code <code>angular.element("#txtData").focus();</code> suppose to work in angular but did not.......do i need to refer any library called <strong>jqLite</strong> ?</p>

<p>i heard jqLite is inbuilt in angular js...is it true. can anyone tell me why the this code did not function <code>angular.element("#txtData").focus();</code> from controller function ?</p>