因此,在看一下typescript中的angularjs指令的一些例子之后,似乎大多数人同意在实现它们时使用函数而不是类.
我更愿意将它们作为一个类,并尝试按如下方式实现它们:
module directives
{
export class search implements ng.IDirective
{
public restrict: string;
public templateUrl: string;
constructor()
{
this.restrict = 'AE';
this.templateUrl = 'directives/search.html';
}
public link($scope: ng.IScope, element: JQuery, attributes: ng.IAttributes)
{
element.text("Hello world");
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在这很好用.但是,我需要有一个具有某些属性的独立范围,我正在努力找出如何在类本身中包含它.
逻辑决定了我可以拥有
public restrict: string;
public templateUrl: string;
Run Code Online (Sandbox Code Playgroud)
我应该有类似的东西:
public scope;
Run Code Online (Sandbox Code Playgroud)
但我不确定这是否正确或如何从那里继续(即如何将属性添加到范围).
谁知道怎么解决这个问题?(希望如果可能的话,不必恢复功能)
谢谢,