I am new to AngularJS and i don't know if "Is controller inheritance a good practice in AngularJS?". I mean that if I have 2 almost the same controllers like here:
someModule.controller('SimilarController1', function($scope) {
$scope.theSameFun1 = function() {
// Some $scope manipulation
};
$scope.theSameFun2 = function() {
// Some $scope manipulation
};
$scope.foo = function() {
// Some $scope manipulation
};
});
someModule.controller('SimilarController2', function($scope) {
$scope.theSameFun1 = function() {
// Some $scope manipulation
};
$scope.theSameFun2 = function() {
// Some $scope manipulation
};
$scope.bar = function() {
// Some $scope manipulation
};
});
then I can write it like this:
someModule.controller('BaseController', function($scope) {
$scope.theSameFun1 = function() {
// Some $scope manipulation
};
$scope.theSameFun2 = function() {
// Some $scope manipulation
};
});
someModule.controller('SimilarController1', function($scope, $controller) {
$controller('BaseController', {$scope: $scope});
$scope.foo = function() {
// Some $scope manipulation
};
});
someModule.controller('SimilarController2', function($scope, $controller) {
$controller('BaseController', {$scope: $scope});
$scope.bar = function() {
// Some $scope manipulation
};
});
Is that "Angular way" to solve this kind of problem?
I have read that repeated parts should be in service/factory. I have also read that passing and manipulating on $scope in service/factory is bad practice, so it's probably not good idea in this situation.