javascript - 使用 TypeScript 和 Angular 1 隔离指令中的范围

标签 javascript angularjs typescript angularjs-directive definitelytyped

尝试使用 TypeScript 创建新的 Angular Directive(指令)时,我遇到了一个问题。仅当我计划在指令中使用隔离范围时才会出现此问题。以下是我正在做的:

module Foo.Layout {
    "use strict";
    class SidebarDirective implements ng.IDirective {

        templateUrl = "/layout/sidebar/sidebar.html";
        restrict = "E";
        controller = SidebarController;
        scope = {
            align: "@"
        }

        static factory() {
            var instance = () => {
                return new SidebarDirective();
            }
            return instance;
        }       
    }
    angular.module("app.layout").directive("fooSidebar", SidebarDirective.factory());
}

该问题仅在添加 scope = {...} 语句时发生,否则编译正常。下面是错误。

Error TS2420 Class 'SidebarDirective' incorrectly implements interface 'IDirective'. Types of property 'scope' are incompatible. Type '{ orientation: string; }' is not assignable to type 'boolean | { [boundProperty: string]: string; }'. Index signature is missing in type '{ orientation: string; }'

是的,在我的输入中 ng.IDirective 具有类型 scope?: boolean | 的 scope 属性{[boundProperty: string]: string};

在我的指令中创建隔离范围的理想方法是什么? (我使用的是 angularjs.TypeScript.DefinitelyTyped 版本 6.5.5)

最佳答案

你试过吗

scope = {
            align: "="
        }

关于javascript - 使用 TypeScript 和 Angular 1 隔离指令中的范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41360680/

相关文章:

javascript - 禁用 future 日期

javascript - Google Map V3 未居中,仅显示 map 的一部分

javascript - 在 Internet Explorer 中使用 JavaScript,如何在不刷新页面的情况下清除内存?

javascript - 从不同页面重定向到页面上的特定选项卡

javascript - 使用来自 DOM 的信息创建一个 Controller /服务来持久化数据

angularjs - Angularjs 中的 Google map 中应用 map 标记后的灰色瓷砖

Angular 2 之后的 angular.element 替代方案

javascript - 根据当前 View 将按钮设置为可见和不可见

javascript - Angular 6,请求httpClient(类型错误)

javascript - 将 id 分配给 id 属性名称可配置的通用类型?