AngularJS error: Template for directive 'XXXXXX' must have exactly one root element

后端 未结 1 1155
野的像风
野的像风 2021-01-21 14:35

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 b
相关标签:
1条回答
  • 2021-01-21 15:06

    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.

    0 讨论(0)
提交回复
热议问题