user1217167
user1217167

Reputation: 83

AngularJS ng-repeat group of TH

I am a new programmer AngularJS, and i have a problem trying to achieve a specific template for a table. I would like to achieve the following table, but can not find how to do it:

<!DOCTYPE HTML>
    <html >
    <head>
       <title></title>
    </head>
    <body >
        <table border="1" width="50%" cellspacing="0" cellpadding="3">
        <tbody>
            <tr>
               <th colspan="33">XXXXXXXXXXXXXXXXXXXXXXX</th>
            </tr>
            <tr>
               <th rowspan="2">&nbsp;</th>
               <th colspan="2">P1</th>
               <th colspan="2">P2</th>
               <th colspan="2">P3</th>
            </tr>
            <tr >
               <th >INFO1</th>
               <th >INFO2</th>
               <th >INFO1</th>
               <th >INFO2</th>
               <th >INFO1</th>
               <th >INFO2</th>
            </tr>           
       </tbody>
       </table
    </body>
    </html>

I have the following code in AngularJS however I can not repeat th because there is no html element that wraps:

    <!DOCTYPE HTML>
    <html ng-app="myApp">
    <head>
    <title></title>
        <script src="js/angular.js"></script>
        <script>
        var app = angular.module('myApp', []);
        app.controller("myCTL",['$scope',function($scope){
            $scope.datas=[{id:'1', name:'P1',pct:'10'},{id:'2', name:'P2',pct:'70'},{id:'3', name:'P3',pct:'66'}]
        }])
        </script>

    </head>
    <body ng-controller="myCTL">
        <table border="1" width="50%" cellspacing="0" cellpadding="3">
           <tbody>
              <tr>
                 <th colspan="33">XXXXXXXXXXXXXXXXXXXXXXX</th>
              </tr>
              <tr>
                 <th rowspan="2">&nbsp;</th>
                 <th colspan="2" ng-repeat="data in datas">{{data.name}}</th>
              </tr>

              <tr>

                  ng-repeat ="data in datas" [START]
                  <th >INFO1</th>
                  <th >INFO2</th>
                  ng-repeat  [END]
              </tr>         
        </tbody>
    </table

    </body>
</html>

Please if anyone knows how to solve this problem would greatly appreciate it. Thanks a lot in advance.

Upvotes: 4

Views: 2897

Answers (1)

Blazemonger
Blazemonger

Reputation: 92913

Use ng-repeat-start and ng-repeat-end:

          <tr>
              <th ng-repeat-start ="data in datas">INFO1</th>
              <th ng-repeat-end>INFO2</th>                  
          </tr>   

Upvotes: 5

Related Questions