2

TypeScriptを使用して新しい角度指示文を作成しようとすると、問題が発生します。この問題は、ディレクティブで分離スコープを使用する予定がある場合にのみ発生します。以下は、私がやっているものです:TypeScriptと角度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()); 
} 

問題は、他のscope = {...}ステートメントを追加するとき、それは罰金コンパイル起こります。以下はエラーになります。

エラーTS2420クラス 'SidebarDirective'が、インターフェイス 'IDirective'を間違って実装しています。プロパティ 'scope'の型は互換性がありません。 タイプ '{orientation:string; } 'は型に代入不可' boolean | {[boundProperty:string]:文字列。 } '。 '{orientation:string;}にインデックスの署名がありません。 }」

そして、はい、私のタイピングにng.IDirectiveはタイプのスコーププロパティにscope?: boolean | {[boundProperty: string]: string};

を持っている私のディレクティブで分離株スコープを作成するための理想的な方法は何ですか?

答えて

0

あなたは

scope = { 
      align: "=" 
     } 
+0

うんで試してみました、それはそれは、コンパイル(活字体)であなたにエラーを与える:( – snippetkid

+0

を動作しませんでした?(私はangularjs.TypeScript.DefinitelyTypedバージョン6.5.5を使用していますか) –

+0

はい、コンパイル時にエラーが発生します – snippetkid

関連する問題