Angularjs, set focus on an input in a table -


i have table input in each cell, can add records table clicking on button. set focus on first input of last record created. don't know if that's possible. if can me on this...

function ctrl($scope) {    $scope.adresses = [];        $scope.add = function() {      var adr = {ville:null, codepostal:null}      $scope.adresses.push(adr);    };      }
<!doctype html>  <html ng-app>    <head>      <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script>      <script src="script.js"></script>      </head>    <body>    <div ng-controller="ctrl" >    <button ng-click="add()"> add </button>    <table>      <tr>                <th>ville</th>        <th>adresse</th>      <tr>            <tr ng-repeat="adresse in adresses">        <td>         <input ng-model="adresse.ville"/>        </td>        <td>         <input ng-model="adresse.codepostal"/>        </td>                     <tr>    </table>      </div>                </body>  </html>

try approach.

controller

controller('appctrl', function ($scope, $timeout, $element) {   $scope.adresses = [];    $scope.add = function() {     var adr = {ville:null, codepostal:null}     $scope.adresses.push(adr);      $timeout(function () {       $element[0].queryselector('[is-last=true]').focus();     })   }; }); 

markup

<input ng-model="adresse.ville" is-last="{{$last}}"/> 

working plnkr


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -