Angular: Empty Fiddle
http://angularjs.org/
by Yashwanth Hari
HTML
<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl">
Hello, {{name}}!
<br/>
<input ng-model='newitem1' />
<input ng-model='newitem2' />
<input ng-model='newitem3' />
<button ng-click='add()'>Add</button>
<br/>
<b>Items Added Below</b>
<div select-last ng-repeat='item in items'>
<input ng-model='item' id='item-{{$index}}' class='input-{{$index}}' />
</div>
</div>
JavaScript
var myApp = angular.module('myApp',[]);
myApp.directive('selectLast', function () {
return function (scope, element, attrs) {
if (scope.$last=== true) {
console.log("the last element is here");
}
}
});
function MyCtrl($scope) {
$scope.name = 'Please try entering something and click Add button';
$scope.items = [];
$scope.newitem1 = '';
$scope.newitem2 = '';
$scope.newitem3 = '';
$scope.add = function(){
$scope.items.push($scope.newitem1,$scope.newitem2,$scope.newitem3);
//fetch last item id using jquery
// var LastIndex = parseInt($scope.items.length) - 1;
// var LastInput = '#item-'+LastIndex;
// if($(LastInput).length == 0){
// alert('Couldnot select the last added DOM element (Input)');
// }else{
// var InputClass = $(LastInput).attr('class');
// alert(InputClass);
// }
}
}