尝试使用 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/