Detailed description of table use in AngularJS

Source: Internet
Author: User

Detailed description of table use in AngularJS

This article mainly introduces how to use tables in AngularJS. As a popular JavaScript framework, AngularJS provides powerful table functions. For more information, see

Table data is usually duplicated in nature. The ng-repeat command can be used to easily draw tables. The following example shows how to use the ng-repeat command to draw a table.

?

1

2

3

4

5

6

7

8

9

10

<Table>

<Tr>

<Th> Name </th>

<Th> Marks </th>

</Tr>

<Tr ng-repeat = "subject in student. subjects">

<Td >{{ subject. name }}</td>

<Td >{{ subject. marks }}</td>

</Tr>

</Table>

You can use the CSS style to set the style of a table as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

<Style>

Table, th, td {

Border: 1px solid gray;

Border-collapse: collapse;

Padding: 5px;

}

Table tr: nth-child (odd ){

Background-color: # f2f2f2;

}

Table tr: nth-child (even ){

Background-color: # ffffff;

}

</Style>

Example

The following example shows all the preceding commands.

TestAngularJS.html

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

<Html>

<Head>

<Title> Angular JS Table </title>

<Style>

Table, th, td {

Border: 1px solid gray;

Border-collapse: collapse;

Padding: 5px;

}

Table tr: nth-child (odd ){

Background-color: # f2f2f2;

}

Table tr: nth-child (even ){

Background-color: # ffffff;

}

</Style>

</Head>

<Body>

<H2> AngularJS Sample Application

<Div ng-app = "" ng-controller = "studentController">

<Table border = "0">

<Tr> <td> Enter first name: </td> <input type = "text" ng-model = "student. firstName "> </td> </tr>

<Tr> <td> Enter last name: </td> <input type = "text" ng-model = "student. lastName "> </td> </tr>

<Tr> <td> Name: </td> <td >{{ student. fullName () }}</td> </tr>

<Tr> <td> Subject: </td> <td>

<Table>

<Tr>

<Th> Name </th>

<Th> Marks </th>

</Tr>

<Tr ng-repeat = "subject in student. subjects">

<Td >{{ subject. name }}</td>

<Td >{{ subject. marks }}</td>

</Tr>

</Table>

</Td> </tr>

</Table>

</Div>

<Script>

Function studentController ($ scope ){

$ Scope. student = {

FirstName: "Mahesh ",

LastName: "Parashar ",

Fees: 500,

Subjects :[

{Name: 'physics ', marks: 70 },

{Name: 'chemistry ', marks: 80 },

{Name: 'Math', marks: 65 },

{Name: 'English ', marks: 75 },

{Name: 'hindi ', marks: 67}

],

FullName: function (){

Var studentObject;

StudentObject = $ scope. student;

Return studentObject. firstName + "" + studentObject. lastName;

}

};

}

</Script>

<Script src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"> </script>

</Body>

</Html>

Output

Open textangularjs.html in the webbrowser and see the following results:

Related Article

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.