I'm pretty new to Angular, so maybe this isn't the best way to approach a problem. I'm trying to access a factory called Devices
from a directive, called topDevices
, scope.
topDevices.js
:
app.directive('topDevices', function() {
return {
restrict: 'E',
scope: {
count: '@',
sortKey: '@',
devices: Devices.sortByKey(this.count, this.sortKey)
},
templateUrl: 'app/directives/topDevices.tpl.html'
}
});
Is this something not normally allowed or just bad practice/approach? Devices
contains a list of devices using Devices.all()
, but I also have a Devices.sortByKey(count, key)
function to return a limited set of devices sorted by a particular key.
EDIT: More info
The purpose of this is to create a template that could list, for example, the top 5 devices by some X metric. The template is this:
<h3>Top {{ count }} by {{ sortKey }}</h3>
<table class="table table-bordered table-condensed table-striped table-hover">
<tbody>
<tr ng-repeat="device in devices">
<td>{{ device.id }}</td>
<td>{{ device.name }}</td>
<td>{{ device[sortKey] }}</td>
</tr>
<tr ng-show="!devices.length">
<td colspan="3">No device info available</td>
</tr>
</tbody>
</table>