Skip to content Skip to sidebar Skip to footer

AngularJS Error: Template For Directive 'XXXXXX' Must Have Exactly One Root Element

This is a follow-up to this question. I am trying to build and HTML with multiple rows. I want some of these rows to be rendered by my directive myDirectiv

Solution 1:

Use this in the app

<table width="40%" border="1">
  <tbody  my-directive-a a="mainCtrl.a">
  </tbody>
</table>

and this in the directive template

<tbody>
<tr>
    <td bgcolor='#7cfc00'>MyDirectiveACtrl.a.b</td>
    <td bgcolor='#ff1493'>{{MyDirectiveACtrl.a.b}}</td>
</tr>
<tr>
    <td bgcolor='#7cfc00'>MyDirectiveACtrl.a.b</td>
    <td bgcolor='#ff1493'>{{MyDirectiveACtrl.a.b}}</td>
</tr>
</tbody>

It allows you to have only one root element in your directive, and add more than one TR inside of it.


Post a Comment for "AngularJS Error: Template For Directive 'XXXXXX' Must Have Exactly One Root Element"