I am working against two lists in SharePoint, so in my project I have three controllers, one main controller, and one for each SharePoint list. My lists are items, and tasks. One item can have several tasks.
When I want to view an item, in the itemList controller I do this:
$scope.loadItem = function(id){
var promise = ItemService.getItem(id);
promise.then(function(item){
$scope.viewItem(item);
}, function(err){console.log(err);})
};
Then, when I want to load tasks I have this in the taskList controller
$scope.loadTasks = function(parentId){
var promise = TaskService.getTasks(parentId);
promise.then(function(result){
console.log(result);
}, function(err){console.log(err);})
};
Here's the problem, when I load my item $scope.loadItem(), I would also want to load tasks related to that item, but that function is in the other controller (to keep things clean).
This is how I'm thinking it would look like:
$scope.loadItem = function(id){
var promise = ItemService.getItem(id);
promise.then(function(item){
$scope.loadTasks(item.Id);
$scope.viewItem(item);
}, function(err){console.log(err);})
};
But I can only make this happen in two ways, and that is by moving my loadTasks function to either the same controller as loadItems function, or to the main controller (cause they both inherit from that), but that would mess up my code.
How can I call the loadTasks function, from my itemList controller, without creating the wrong functions in the wrong controllers, and thus messing up my code?