<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Colores web</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script src="script.js"></script>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body ng-app="app">
<div class="container">
<div class="table-responsive" ng-controller="groupColorsController">
<table class="table table-condensed table-bordered" ng-repeat="colors in colors">
<thead>
<tr>
<th colspan="3"><h3><strong>Colores {{colors.name}}</strong></h3></th>
</tr>
<tr>
<th>Nombre</th>
<th>Código hexadecimal</th>
<th>ID</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="color in colors.color" ng-controller="colorController" style="background-color:{{color[0]}}" ng-init="count = $index+1">
<td>{{color[0]}}</td>
<td>{{color[1]}}</td>
<td>{{id}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
// Code goes here
angular.module('app', [])
.controller('groupColorsController', function groupColors($scope){
$scope.colors = [
{name : "rojos", color : [
["IndianRed", "CD5C5C"],
["LightCoral", "F08080"],
["Salmon", "FA8072"]
]},
{name : "rosados", color : [
["Pink", "FFC0CB"],
["LightPink", "FFB6C1"],
["HotPink", "FF69B4"]
]},
{name : "narajnas", color : [
["Coral", "FF7F50"],
["Tomato", "FF6347"],
["OrangeRed", "FF4500"]
]}
];
})
.controller('colorController', function($scope) {
// $scope -> scope de colorController
// $scope.$parent -> scope de ng-repeat interior
// $scope.$parent.$parent -> scope de ng-repeat exterior
// $scope.$parent.$parent.$parent -> scope de groupColorsController
$scope.id = 0
for(var i = 0; i < $scope.$parent.$parent.$index; ++i) {
console.log($scope.$parent.$parent.$parent.colors[i].color.length)
$scope.id += $scope.$parent.$parent.$parent.colors[i].color.length
}
console.log($scope.$index)
$scope.id += $scope.$index + 1;
});
/* Styles go here */
.container {
max-width: 970px;
}
.light-color {
color: white;
}
body {
color: black;
}
.table {
margin-bottom: 0;
}