When I am creating an AngularJS directive using TypeScript, I typically use the bindToController
property to bind parameters to the controller for easy access.
export class MyDirective implements IDirective {
controller = MyController;
controllerAs = 'vm';
bindToController = {
paramOne: '<',
paramTwo: '<'
};
}
export class MyController {
paramOne: boolean; // these params are now set and ready to be used
paramTwo: boolean;
...
}
Recently, I discovered that the bindToController
parameter of the IDirective
interface is deprecated, even though it still functions as expected.
/**
* @deprecated
* Deprecation warning: although bindings for non-ES6 class controllers are currently bound to this before
* the controller constructor is called, this use is now deprecated. Please place initialization code that
* relies upon bindings inside a $onInit method on the controller, instead.
*/
The deprecation message is clear but I'm still unclear on why this decision was made.
Could someone clarify why bindToController
is now deprecated and provide guidance on the best approach moving forward?