Ich habe ein Problem, wenn ich versuche, eine neue eckige Direktive mit TypeScript zu erstellen. Das Problem tritt nur auf, wenn ich den isolate-Bereich in der Direktive verwenden möchte. Es folgt, was ich tue:Bereich in Richtlinie mit TypeScript und Angular isolieren 1
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());
}
Das Problem tritt nur auf, wenn das Hinzufügen der scope = {...}
Anweisung sonst kompiliert es in Ordnung. Unten geht der Fehler.
Fehler Die TS2420-Klasse 'SidebarDirective' implementiert die Schnittstelle 'IDirective' falsch. Arten der Eigenschaft 'Geltungsbereich' sind nicht kompatibel. Typ '{orientation: string; } 'ist nicht dem Typ' boolean | {[boundProperty: string]: string; } '. Die Indexsignatur fehlt im Typ '{orientation: string; }‘
Und ja in meiner Typisierung ng.IDirective
den Umfang Eigenschaft des Typs hat scope?: boolean | {[boundProperty: string]: string};
Was ist der ideale Weg, um einen Isolat Umfang in meiner Richtlinie zu schaffen? (Ich bin mit dem angularjs.TypeScript.DefinitelyTyped Version 6.5.5)
yup und es hat nicht funktioniert :( – snippetkid
geben Sie einen Fehler bei der Kompilierung (Typoskript)? –
ja es gibt Fehler beim Kompilieren – snippetkid