0

How to load the multipe array data to the directive templateURL using ngrepeat

<div> <table> <tr> <td>h1</td> <td>v1</td> </tr> </table> </div>
<div> <table> <tr> <td>h2</td> <td>v2</td> </tr> </table> </div>
<div> <table> <tr> <td>h3</td> <td>v3</td> </tr> </table> </div>

DEMO LINK

Directive Controller:

 $scope.data  =[[{ h:'H1', v:'V1'}][{ h:'H2', v:'V2'}][{ h:'H3', v:'V3'}]];
 $scope.updateData = $scope.data;

Template Structure:

  <div ng-repeat="fields in updateData">
      <table>
      <tr>
          <td>{{f.h}}</td>
          <td>{{f.v}}</td>
      </tr>
    </table></div>
2

1 Answer 1

2

Just add another ng-repeat on the <tr>

<div ng-repeat="fields in updateData">
      <table>
           <tr ng-repeat="f in fields">
              <td>{{f.h}}</td>
              <td>{{f.v}}</td>
           </tr>
       </table>
  </div>

DEMO

Sign up to request clarification or add additional context in comments.

2 Comments

how can I make my directive to wait for until the controller loads the value from service and binds to the view?
@John Smith: you don't need to wait, angular is smart enough to automatically update the views when the models are ready.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.