【发布时间】:2014-06-25 12:06:17
【问题描述】:
因此,在查看了 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");
}
}
}
现在这工作正常。但是,我需要一个具有某些属性的隔离范围,并且我正在努力找出如何将其包含在类本身中。
逻辑决定了,因为我可以拥有
public restrict: string;
public templateUrl: string;
我应该能够拥有类似的东西:
public scope;
但我不确定这是否正确或如何从那里继续(即如何将属性添加到范围)。
有人知道怎么解决吗? (希望,如果可能,不必恢复到函数)
谢谢,
【问题讨论】:
标签: angularjs typescript