In AngularJS >1.5, how can several related components share a common controller with common functionallity while being able to have custom behavior for every distinct component?
For example implementing components for <input> elements of different types (text, number, date ... ), every controller will share the same functionallity (to propagate the component value to parent on value changes for example) so one can write a function for the controller and use it on all of them. But if a custom behavior is needed for some types. How can it be detected which component does the controller belong?
Here is some psudo-code:
var commonController = function() {
this.$onInit = function() {
// common code for all types
// code for a specific type
// how can I detect here which component is running?
}
}
angular.module('app')
.component('component01', {
controller: commonController),
...
})
.component('component02', {
controller: commonController),
...
})
.component('component03', {
controller: commonController),
...
})