[英]Isolate scope in Directive with TypeScript and Angular 1
I am stuck on an issue when trying to create a new angular directive using TypeScript. 尝试使用TypeScript创建新的angular指令时,我遇到了一个问题。 The issue only happens if I am planning to use the isolate scope in the directive.
仅当我计划在指令中使用隔离范围时,才会发生此问题。 Following is what I am doing:
以下是我在做什么:
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());
}
The issue only happens when adding the scope = {...}
statement else it compiles fine. 仅当添加
scope = {...}
语句时才会发生此问题,否则可以正常编译。 Below goes the error. 下面是错误。
Error TS2420 Class 'SidebarDirective' incorrectly implements interface 'IDirective'.
错误TS2420类“ SidebarDirective”错误地实现了接口“ IDirective”。 Types of property 'scope' are incompatible.
属性“作用域”的类型不兼容。 Type '{ orientation: string;
输入'{方向:字符串; }' is not assignable to type 'boolean |
}“不能分配给'boolean | { [boundProperty: string]: string;
{[[boundProperty:string]:string; }'.
}”。 Index signature is missing in type '{ orientation: string;
类型'{方向:字符串; }'
}”
And yes in my typings ng.IDirective
has the scope property of type scope?: boolean | {[boundProperty: string]: string};
是的,在我的
ng.IDirective
具有类型scope?: boolean | {[boundProperty: string]: string};
的scope属性scope?: boolean | {[boundProperty: string]: string};
scope?: boolean | {[boundProperty: string]: string};
What is the ideal way to create an isolate scope in my directive? 在我的指令中创建隔离作用域的理想方法是什么? (I am using the angularjs.TypeScript.DefinitelyTyped version 6.5.5)
(我正在使用angularjs.TypeScript.DefinitelyTyped版本6.5.5)
Have you tried with 你尝试过
scope = {
align: "="
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.