繁体   English   中英

具有隔离范围的Angular Typescript指令在编译时生成Typescript错误

[英]Angular Typescript Directive with Isolate Scope generates Typescript errors on compile

我正在使用Typescript和Angular,尝试通过(其中包括)以下此处的accessibility icon指令使网站更易于访问。

module app.directives {
    export class AccessibleIconDirective implements ng.IDirective {
        priority = 0;
        restrict = 'E';
        scope: { name: '@', text: '@'};
        template: '<i class="fa fa-{{name}}"></i><span class="invisible">{{text}}</span>';
    }
}

Typescript编译器不喜欢隔离范围,并给我以下错误。

accessibleIcon.ts(5,24): error TS1110: Type expected.
accessibleIcon.ts(5,27): error TS1005: ';' expected.
accessibleIcon.ts(5,35): error TS1110: Type expected.
accessibleIcon.ts(8,1): error TS1128: Declaration or statement expected.

我不确定如何在此结构中为类型提供name: '@'text:'@' ,而我不知为什么TS希望在范围对象中使用分号,或者在模块后使用声明。

我正在实现ng.IDirective接口,因此我希望它能够处理隔离范围。

有任何想法吗? 谢谢!

作为参考,这是angular.d.ts中的IDirective接口:

interface IDirective {
    compile?: IDirectiveCompileFn;
    controller?: any;
    controllerAs?: string;
    bindToController?: boolean|Object;
    link?: IDirectiveLinkFn | IDirectivePrePost;
    name?: string;
    priority?: number;
    replace?: boolean;
    require?: any;
    restrict?: string;
    scope?: any;
    template?: any;
    templateNamespace?: string;
    templateUrl?: any;
    terminal?: boolean;
    transclude?: any;
}

您正在使用:应该何时使用= 这些应该是属性初始值设定项,而不是类型注释。

module app.directives {
    export class AccessibleIconDirective implements ng.IDirective {
        priority = 0;
        restrict = 'E';
        // fixed
        scope = { name: '@', text: '@'};
        // fixed
        template = '<i class="fa fa-{{name}}"></i><span class="invisible">{{text}}</span>';
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM