Implement custom display with Ng-repeat-start in Angular.js _angularjs

Source: Internet
Author: User

Objective

It is well known that ANGULARJS can be used to ng-repeat display list data, which should be familiar to everyone, it is very simple and convenient to use, for example, to display a product table, Controller's Javascript code is as follows:

Angular.module (' app ', [])
. Controller (' Mycontroller ', mycontroller);

Mycontroller. $inject = [' $scope '];
function Mycontroller ($scope) {
 //Product list data to display;
 $scope. Products = [
  {
   id:1,
   name: ' Product 1 ', C12/>description: ' Product 1 description. '
  },
  {
   id:2,
   name: ' Product 3 ',
   Description: ' Product 2 description. '
  },
  {
   id:3,
   name: ' Product 3 ',
   Description: ' Product 3 description. '
  }
 ];
}

The corresponding HTML view code is as follows:

 <table class= "Table" >
  <tr>
   <th>id</th>
   <th>name</th>
   <th >description</th>
   <th>action</th>
  </tr>
  <tr ng-repeat= "p in Products" >
   <td></td>
   <td></td>
   <td></td>
   <td><a href= " # ">Buy</a></td>
  </tr>
 </table>

Run Effect chart:

But if all the pages are in one row for each product, it's too boring, like the user wants to customize the display:

Each product occupies two rows of the table, so the effect can not be realized with ng-repeat. However, Angularjs provides ng-repeat-start and ng-repeat-end to implement the above requirements, ng-repeat-start and ng-repeat-end The syntax is as follows:

  
 

Assuming that [' a ', ' B '] two products are provided, the resulting HTML results are as follows:

  
 

After understanding ng-repeat-start the ng-repeat-end usage, the required interface is easy to implement and the code is as follows:

 <table class= "Table table-bordered" >
  <tr ng-repeat-start= "p in Products" >
   <td></td>
   <td rowspan= "2" ><a href= "#" >Buy</a></td>
  </tr>
  <tr ng-repeat-end >
   <td></td>
  </tr>
 </table>

Summarize

The above is angular.js in the use of Ng-repeat-start to achieve a custom display of all the content, I hope the content of this article for everyone to learn or use angular.js can help, if there are questions you can message exchange, thank you for your support cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.