加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

将Anglejs指令实现为Typescript中的类

发布时间:2020-12-17 08:07:44 所属栏目:安全 来源:网络整理
导读:所以在看了一些在typedcript中的angularjs指令的例子中,似乎大多数人同意在实现它们时使用函数而不是类。 我宁愿把他们当成一个班级,并试图按照下列方式实施: module directives{ export class search implements ng.IDirective { public restrict: strin
所以在看了一些在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");
        }
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读