所以在看了一些在typedcript中的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;
但我不知道这是正确的还是从那里进行的(即如何将属性添加到范围)。
有谁知道如何解决这个问题? (希望,如果可能的话,不需要恢复功能)
谢谢,
假设您在没有异步范围的情况下工作,以下内容应与隔离范围配合使用:
module directives
{
export class search implements ng.IDirective
{
public restrict = 'AE';
public templateUrl = 'directives/search.html';
public scope = {
foo:'=',bar:'@',bas:'&'
};
public link($scope: ng.IScope,attributes: ng.IAttributes)
{
element.text("Hello world");
}
}
}