I would like to add a row dynamically to a table. I would like to reuse the row in a few tables.
I tried doing this with a directive and by using ng-include but neither option worked as I expected.
Basically, this is what I did:
myapp.directive('myRow', function () {
return {
restrict : 'E',
replace : true,
scope : { mytitle : '@mytitle'},
template : '<tr><td class="mystyle">{{mytitle}}</td></tr>'
}
});
and in html:
<table>
<tbody>
<tr><td>data</td></tr>
<my-row></my-row>
</tbody>
</table>
The <tr> element gets drawn but ends up outside the <table> element in the dom.
Is there a simple way to include table rows using angularjs?
<tr></tr>it must be</td></tr>You cannot have 2 root elements in the template. Just check your console, you will get all kinds of clues there itself. plnkr.co/edit/pCNbci?p=preview