Tuesday, April 21, 2015

AngularJs tables with ne-repeat

<html>
<title> AngularJs Directives </title>
<head>
<title>Angular JS Table</title>
<style>
table, th , td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd) {
background-color: #f2f2f2;
}
table tr:nth-child(even) {
background-color: #ffffff;
}
</style>
</head>
<body>

<div ng-app="" ng-controller="firstController">

<table>
<tr>
<th>
Name
</th>
<th>
Marks
</th>
</tr>
<tr ng-repeat="item in data.subject">

<td>
{{ item.name}}
</td>

<td>
{{ item.marks }}
</td>

</tr>


</table>


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

<script>


function firstController($scope)
{

$scope.data={
firstname:'Shekhar',
lastname:'Nawale',
subject:[{name:'Physics',marks:'40' },{name:'Chemistry',marks:'50' },{name:'Math',marks:'60' },{name:'Biology',marks:'70' }],
fees:'100',
fullname: function()
{
var name=$scope.data;
return name.firstname + ' ' + name.lastname;
}
};
}

</script>

</body>
</html>

No comments:

Post a Comment