This is something I discovered when trying to make my controllers more reusable.
app.factory('BaseController', function(myService) {
return function(variable) {
this.variable = variable;
this.method = function() {
myService.doSomething(variable);
};
};
})
.controller("ChildController1", function($scope, BaseController) {
BaseController.call($scope, "variable1");
})
.controller("ChildController2", function($scope, BaseController) {
BaseController.call($scope, "variable2");
});
And now I can do something like this in my HTML (e.g inside ng-controller="ChildController1"): ng-click="method()"
The code simply works. But I don't know how it really works (what kind of pattern is it?) and would it be a good practice to do so?