[英]Isolate scope in Directive with TypeScript and Angular 1
嘗試使用TypeScript創建新的angular指令時,我遇到了一個問題。 僅當我計划在指令中使用隔離范圍時,才會發生此問題。 以下是我在做什么:
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 = {...}
語句時才會發生此問題,否則可以正常編譯。 下面是錯誤。
錯誤TS2420類“ SidebarDirective”錯誤地實現了接口“ IDirective”。 屬性“作用域”的類型不兼容。 輸入'{方向:字符串; }“不能分配給'boolean | {[[boundProperty:string]:string; }”。 類型'{方向:字符串; }”
是的,在我的ng.IDirective
具有類型scope?: boolean | {[boundProperty: string]: string};
的scope屬性scope?: boolean | {[boundProperty: string]: string};
scope?: boolean | {[boundProperty: string]: string};
在我的指令中創建隔離作用域的理想方法是什么? (我正在使用angularjs.TypeScript.DefinitelyTyped版本6.5.5)
你嘗試過
scope = {
align: "="
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.