
有一个可行的例子
我只是稍微调整了一下代码-即可正常工作:
namespace MyNamespace { export class MyDirectiveController { public value:string; static $inject = ['$scope']; constructor(private $scope: ng.IScope) { // I wanna do something with this.value at this point // NOW It is defined console.log(this.value); $scope.$watch('value', this.valueDidChangeCallback).bind(this); } valueDidChangeCallback:any = () => { // Now I can do the thing I wanted to do ... console.log(this.value); }; } export class MyDirectiveDirective { restrict: string = 'E'; templateUrl: string = 'my-directive.html'; controller = MyNamespace.MyDirectiveController; controllerAs: string = 'vm'; bindToController: boolean = true; scope:any = { 'value': '=' }; } angular .module('MyApp') .directive('myDirective', [() => {return new MyNamespace.MyDirectiveDirective()}])}欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)