i'm trying to create a table directive for my app, i would like to make it really flexible so, i can use it everywhere. The thing is that i don't know how to access the data from the string i'm trying to pass, maybe it's not the best way... any suggestions? Here is the code of both, html and directive:
'use strict';
angular.module("private.directives")
.directive('tableDirective', [
function(){
return {
restrict : 'E',
templateUrl: 'resources/js/private/views/utils/table/table.html',
scope : {
selected: '=',
page : '=',
header : '=',
properties : '='
},
controller : ['$scope', function ($scope) {
}],
controllerAs : 'cntrl',
bindToController: true
}
}]);
The table html:
<div class="pt-1">
<table class="table table-hover">
<thead>
<tr ng-repeat="header in headers">
<th translate>{{header | uppercase}}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="data in cntrl.page.data" ng-class-odd="'striped'">
<td>{{data.[cntrl.properties[$index]] | uppercase}}</td>
</tr>
</tbody>
</table>
<!-- TODO -->
<div class="row" ng-show="cntrl.page.totalResults > 0">
<div class="col-xs-12">
<nav class="float-xs-right" aria-label="Page navigation">
<ul class="pagination">
<li class="page-item">
<a class="page-link" href="#" aria-label="Previous">
<span aria-hidden="true">«</span>
<span class="sr-only" translate>paginacion.previous</span>
</a>
</li>
<li class="page-item active"><a class="page-link" href="#">1</a></li>
<li class="page-item"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item">
<a class="page-link" href="#" aria-label="Next">
<span aria-hidden="true">»</span>
<span class="sr-only" translate>paginacion.next</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
And the HTML where is called:
<table-directive
page="cntrl.ingredients"
headers="['#', 'table.name', 'tabla.brand']"
properties="['ingredientId','description','brandDescription']">
</table-directive>
The data in the "cntrl.ingredients" is an object with the followings:
{
data : [],
currentPage : null,
pageSize : null,
totalResults : null,
sortDirection : null,
orderBy : null
}
Where the "data" array will have diferent objects depending the table i'm using. I know the error is in the table html when i iterate over the cntrl.page.data, i don't know how to get the value i want to be show... "data.[cntrl.properties[$index]]" does not seem to be working.
Thanks in advance!!