How to set focus on a text input in a list with AngularJS and HTML5

AngularJavascriptWeb DevelopmentFront End Scripts

To set focus on a text input in a list, try the following code:

newApp.directive('focus', function () {
   return function (scope, element, attrs) {
      attrs.$observe('focus', function (newValue) {
         newValue === 'true' && element[0].focus();
      });
   }
});

The following is the HTML:

<input type="text" ng-model="cues[$index].text" focus="{{cue.isNewest}}"
class="input-xlarge" />{{cue.isNewest}}
raja
Published on 10-Apr-2018 08:11:03
Advertisements