使用bindToController时,构造函数中未定义指令的作用域变量

使用bindToController时,构造函数中未定义指令的作用域变量,第1张

使用bindToController时,构造函数中未定义指令的作用域变量

有一个可行的例子

我只是稍微调整了一下代码-即可正常工作:

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()}])}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5016124.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-15
下一篇2022-11-14

发表评论

登录后才能评论

评论列表(0条)

    保存