Suppose I have two different view controllers, whereas both use the same function within their scopes, e.g. set some scope variable, something like this:
View1Cntr.js
app.controller('View1Cntr', ['$scope', function($scope) {
$scope.coloredContent = []; // default
// View1Cntr custom code here
$scope.clearColoredContent = function() {
$scope.coloredContent = [];
}
}]);
View2Cntr.js
app.controller('View2Cntr', ['$scope', function($scope) {
$scope.coloredContent = []; // default
// View2Cntr custom code here
$scope.clearColoredContent = function() {
$scope.coloredContent = [];
}
}]);
Is there any way I could only define the function once and pass it to both controllers, so that the maintenance becomes easier?
I guess, this is a closure case (please, correct me if I am wrong) and that is why I am not sure how to get around it.
Thanks!