angularjs - Giving unique id to each item in `ng-repeat` for DOM manipulations -


.div(ng-repeat='item in items')     button(id='id{{$index}}') no hi  button(id='anotherid1') hi 

inside relevant angular directive

$('#id1').on('click', function() {alert('hi');});  // not work   $('#anotherid1').on('click', function() {alert('hi');}); // works 

i performing dom manipulations need unique id ng-repeat elements. please suggest if dom manipulation can performed in other way too.

edit: @tymejv:-

 style.   .ques {     height: 50px;     overflow:hidden;   }    <div ng-repeat='item in items'>     <div class='ques'> {{item.ques}}     </div>     <button id='id{{$index}}'> no hi </button> </div> 

// directive code:- increase height of <div class = 'ques'>

first of all, if using angular, recommended stick standard angular directives listeners rather reverting jquery. instead of jquery's on, use ng-click attribute on html events want angular bind listener to.

for example:

html:

<button ng-click="dostuff()"> </button> 

controller:

$scope.dostuff = function () {     //perform action }; 

for storing unique id each element created ng-repeat, how adding parameter dostuff call id: ng-click="dostuff(item.id)" , access in $scope.dostuff method.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -