微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将Anglejs指令实现为Typescript中的类

所以在看了一些在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");
        }
    }
}

原文地址:https://www.jb51.cc/angularjs/144214.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐