[英]Angular typescript directive scope empty
I'm trying to implement a typescript directive, but I can't seem to pass my vars to the directive, this is my current directive 我正在尝试实现一个Typescript指令,但似乎无法将vars传递给该指令,这是我当前的指令
namespace app {
'use strict';
export interface IMyScope {
// ngModel: Date;
testing: string;
}
class DateTime implements angular.IDirective {
public restrict: string = 'E';
public template: string = '<div>Input: {{testing | json}}</div>';
public scope: any = {
testing: '='
};
// @ngInject
controller: any = ($scope: IMyScope): void => {
console.log($scope.testing);
};
link: any = (scope: IMyScope ,
element: angular.IAugmentedJQuery,
attrs: angular.IAttributes,
ctrl: any): void => {
console.log(scope.testing);
}
}
angular
.module('app')
.directive('dateTime', [() => new DateTime()]);
}
but the logs in my link and controller return undefined
any clues why this is happening? 但是我的链接和控制器中的日志返回undefined
任何线索为什么会发生这种情况?
Your code seems to be working as is. 您的代码似乎按原样工作。 There is a working plunker 有一个正在工作的矮人
Just, if the testing
attribute is not set.. it has undefined
value 只是,如果未设置testing
属性,则它具有undefined
值
date-time without attr testing
<date-time ></date-time>
date-time with attr testing="'xxx'"
<date-time testing="'xxx'"></date-time>
Ie just set the testing
attribute 即只是设置testing
属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.