【发布时间】:2016-12-15 13:16:53
【问题描述】:
当我使用 typescript 创建 angularjs 指令时,我使用属性 bindToController 将参数绑定到控制器,以便我可以访问它们
export class MyDirective implements IDirective {
controller = MyController;
controllerAs = 'vm';
bindToController = {
paramOne: '<',
paramTwo: '<'
};
}
export class MyController {
paramOne: boolean; // theses params are now set and I can use them
paramTwo: boolean;
...
}
但现在我意识到接口IDirective的参数bindToController已被弃用,尽管它仍然有效。
/**
* @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.
*/
消息应该解释它,但我还是不明白。
谁能解释为什么不推荐使用它以及最好的方法是什么?
【问题讨论】:
标签: angularjs typescript binding