I've looked at the questions and documentation for extending a 3rd-party Angular directive. What I really need to do though is extend a 3rd-party Angular controller.
I'm using the Smart Table library in my application and its suggestion for implementing list row selection with checkboxes. My application however, requires two types of selections:
- Checkbox selection, where checkboxes can be used to select a single or multiple rows (already covered with the csSelectAll directive in the link above)
- Row highlighting, where only a single row can be highlighted
It would be easy for me to write a highlight function for the stTableController
based on the select method. But I would like to be able to do this without forking Smart Table myself.
I tried the solution for extending controllers, but it appears to assume that the parent and child controller live in the same module. When I try the following code:
angular.module('myApp')
.controller('smarterTableController', function(<required deps>) {
$controller('smartTableController', {$scope: $scope}));
//initialization stuff left out...
this.highlight = function(row) {
var rows = copyRefs(displayGetter($scope));
var index = rows.indexOf(row);
if (index !== -1) {
row.isHighlighted = row.isHighlighted !== true;
if (lastHighlighted) {
lastHighlighted.isHighlighted = false;
}
lastHighlighted = row.isHighlighted === true ? row : undefined;
}
};
});
//corresponding extension of the stTable directive to use the smarterTableController
This solution doesn't appear to work though. When I call the parent controller's function using $controller
, I get the error:
Argument 'smartTableController' is not a function, got undefined
Here are my two questions:
- Should I be able to extend a 3rd-party controller in this way?
- If not, is forking the project and adding this extra bit of functionality my only other option?