I am finding this pattern to be quite convenient, but I am wondering if it will come around to bite me later:
app.controller('MyController', function($scope, $stateParams, MyPageService){
var foo = MyPageService.foo($scope);
scope.bar = function(opts){
return foo(opts);
};
$scope.baz = MyPageService.baz($scope, $stateParams);
});
where MyPageService looks like:
app.factory('MyPageService', function(MySharedService){
return {
foo: function($scope){
return function(opts){
return MySharedService.xyz(opts.v);
}
},
baz: function($scope, $stateParams){
return function(opts){
return MySharedService.ijk(opts.z);
}
}
}
});
this is Angular, but again, this is also just JavaScript, so this should work and has been working in my brief testing of this pattern.
Is there anything that someone might see as "wrong" with this pattern? Any future pitfalls that might go otherwise unforeseen?
I have to say, this pattern is working very well as it stands now. The motivation to do this of course, is because our controller code was becoming massive and it was becoming very necessary to break things out in to pieces. This seemed like the most natural way to do it.