javascript - Angular Controller Scope -


i new angular js , binding following json html:

{     "companyname": "company ltd.",     "products": [         {             "productid": 1245,             "name": "trial",             "productitems": [                 {                     "productid": 1254,                     "productitemname": "service 1",                     "productitemtype": "service"                 },                 {                     "productid": 7789,                     "productitemname": "service 2",                     "productitemtype": "service"                 }             ]         }     ] } 

my html table following:

<table ng-controller="productcontroller productctrl">     <thead>         <tr>             <th id="companyname">                 <h1 class="h1">{{productctrl.data.companyname}}</h1>             </th>             <th ng-repeat="product in productctrl.data.products">                                         <h2>{{product.name}}</h2>                 <h3>                     <span>{{product.productprice}}</span>                     <span> {{product.currencysymbol}} / {{product.pricetimeperiod}} </span>                 </h3>             </th>         </tr>     </thead>     <tbody>         <!--  need `product` here can loop on productitems -->         <tr ng-repeat="item in product.productitems">             <td>{{item.productitemname}}</td>             <td>{{item.amount}}</td>         </tr>     </tbody>     <tfoot>                     </tfoot> </table> 

foreach product in products generating column in thead , each of item in productitems of each product want generate row in tbody since loop on products limited thead cannot bind productitems properly.

any suggestion how overcome this?

ideally maximum product items count product can have in json has known before rendering tbody rows, row created each productitem of product.

check out plunker sample: http://plnkr.co/edit/pl6t69shuje0wlqdwedu?p=preview

the sample logic rendering given below.

<table ng-controller="tblcntrl" class="table">       <thead>         <tr>           <th colspan="2" ng-repeat="product in json.products">{{product.name}}</th>         </tr>         <tr>           <th ng-repeat-start="product in json.products">item name</th>           <th ng-repeat-end>amount</th>         </tr>       </thead>       <tbody>         <tr ng-repeat="item in items">           <td ng-repeat-start="product in json.products">{{product.productitems[$parent.$index].productitemname}}</td>           <td ng-repeat-end>{{product.productitems[$parent.$index].amount}}</td>         </tr>       </tbody>     </table> 

Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -