I am trying to add an additional <tr> element when user click an link inside a td.
I have something like in html
<tr ng-repeat="test in tests">
<td ng-repeat="item in test">
<a item-detail href='' ng-click='open()'>{{item.name}}<a>
</td>
</tr>
so my actually html is like
<tr>
<td><a item-detail href='' ng-click='open()'>1</a></td>
<td><a item-detail href='' ng-click='open()'>2</a></td>
<td><a item-detail href='' ng-click='open()'>3</a></td>
<td><a item-detailhref='' ng-click='open()'>4</a></td>
</tr>
<tr>
<td><a item-detail href='' ng-click='open()'>5</a></td>
<td><a item-detail href='' ng-click='open()'>6</a></td>
<td><a item-detail href='' ng-click='open()'>7</a></td>
<td><a item-detail href='' ng-click='open()'>8</a></td>
</tr>
…more
My goal is to put new new tr tag between two tr tag when user click a button so it will be like
//click any of link here inside a td, add new tr next to it
<tr>
<td><a item-detail href='' ng-click='open()'>1</a></td>
<td><a item-detail href='' ng-click='open()'>2</a></td>
<td><a item-detail href='' ng-click='open()'>3</a></td>
<td><a item-detail href='' ng-click='open()'>4</a></td>
</tr>
<tr><td colspan="4">Newly added</td></tr> <- add one if I click 1,2,3,4
<tr>
<td><a item-detail href='' ng-click='open()'>5</a></td>
<td><a item-detail href='' ng-click='open()'>6</a></td>
<td><a item-detail href='' ng-click='open()'>7</a></td>
<td><a item-detail href='' ng-click='open()'>8</a></td>
</tr>
<tr><td colspan="4">Newly added</td></tr> <- add one if I click 5,6,7,8
my js
angular.module('myApp').directive('itemDetail', function() {
return {
restrict: 'A',
link: function(scope, elem) {
var html = '<tr><td> newly added </td></tr>'
elem.bind('click', function() {
//not sure what to do here. there is no closet method in Jquery lite
})
}
};
}
);
I am not sure how to accomplish this by using directive. Any tips? Thanks a lot!
tr, or do you also want to display details about the selected item in thattr?