I am trying to wrap an angular object into a template which I should then be able to instantiate by using a directive. In this case each directive is a type of widget.
The problem comes from the fact that the directives I am writing are based on the same type, so when instantiating a directive I am keeping a track of the widget object in the global scope. I have something in the lines of:
.directive('lineChart', ['$interval', '$compile', 'widgetDataService',
return {
restrict: 'E',
scope: false,
templateUrl: 'templates/lineChart.html',
link: function(scope, elm, attrs) {
var obj = {
guid: attrs['guid'],
datasource: undefined
}
scope.widgets.push(obj)
...
So then in the template I can do:
...
k-data-source="widgets[{{index}}].datasource"
...
The idea here being that consequent uses of the directive would result in sequentially initialised templates - and therefore each template would get its respective index. However this doesn't work. If I use a directive more than once all instantiated templates get the last index, which probably means that angular is separating the instantion in different stages.
Is there a way to use a global object to keep track of the underlying objects of the directives, but still let them have different indexes passed in at runtime?