Ng-Focus-3

 

In this example of Ng-Focus, We are setting focused variable to true on focus and false on blur of textbox. See the code

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> </head> <body ng-app="myApp"> <div ng-controller="myController"> <div class="container"> Focus me <input class="form-control" type="text" ng-focus="focused = true" ng-blur="focused = false" /> <pre ng-show="focused">I'm focused</pre> </div> </div> <script> var app = angular.module("myApp", []); app.controller('myController', ['$scope', function ($scope) { }]); </script> </body> </html>
Output