i'm wondering if there is a good practice solution for the following situation in AngularJs:
I have a html that is basically displaying a list of elements and a controller that is the view-model and handles certain events for that list. I use this html/controller combination on different spots within my app by using ng-include.
List.html:
<div ng-controller="listController">
<!--... display List here-->
</div>
Now I have been using events from the parent scope to fill the list controller with elements.
ListController.js
angular.module("app").controller('listController', function($scope) {
let $scope.elements = [];
$scope.$on('setElementsEvent', function(event, data) {
$scope.elements = data;
});
});
This has been working fine so far. But now I have the situation, that one parent controller has multiple of these Lists as children, but I want them to display distinct elements. With broadcasting events I would always set the elements for all child lists! Using a factory would pose the same problem, since all of the listControllers have the same controller function.
parent.html
<div ng-controller="parentController">
<!--first list-->
<div ng-include='"List.html"'></div>
<!-- second list -->
<div ng-include='"List.html"'></div>
</div>
Is there a way to get this done without having to write a new controller for every list I want to display?