2017-01-17 2 views
0

私はDashboardLayoutStyleCalculatorServiceというサービスを以下の方法で持っています。サービス内のメソッドをCoffeescriptのディレクティブから呼び出すときのエラー

指令1:このサービスは、2つの異なるディレクティブによって呼び出される

styleFns = 
    table: @computeStyleForTable 
    single_value: @computeStyleForSingleValue 

    @computeStyleFor = (type, height = null) -> 
    return styleFns[type](height) 

:彼らは質問には本当に関連していないだから他の方法は、削除

scope.computeStyle = (component) -> 
    if component?.height? 
    height = component.height * 50 
    return DashboardLayoutStyleCalculator.computeStyleFor(component.element.type, height) 

指令2:

scope.computeStyle = (element, rowComponent) -> 
    return DashboardLayoutStyleCalculator.computeStyleFor(element.type, rowComponent?.height?) 

私のコードがナットシェルで行うことは、入力タイプに依存します。wi薄いcomputeStyleForでは、テーブルまたは単一の値の視覚化の2つの異なるメソッドを呼び出します。また、この質問には完全には必要ではない特定のパラメータに基づいた動的な高さ計算もあります。

私は私のブラウザでこのコードを実行すると、私は次のエラーを取得する:

main.webpack-a9f3967e.js:27 TypeError: e[t] is not a function 
    at Object.computeStyleFor (https://localhost:54321/webpack/main.webpack-a9f3967e.js:10:17938) 
    at e.t.computeStyle (https://localhost:54321/webpack/main.webpack-a9f3967e.js:10:16879) 
    at fn (eval at compile (https://localhost:54321/webpack/vendor.webpack-6f544239.js:49:29700), <anonymous>:4:627) 
    at d.$digest (https://localhost:54321/webpack/vendor.webpack-6f544239.js:48:11027) 
    at d.$apply (https://localhost:54321/webpack/vendor.webpack-6f544239.js:48:12692) 
    at https://localhost:54321/webpack/vendor.webpack-6f544239.js:47:23881 undefined 

computeStyleForまたはstyleFnsのいずれかで問題があると表示されます。私はあなたの呼び出しcomponent.element.type

@computeStyleFor = (type, height = null) -> 
    return styleFns[type](height) 
        ^^^^^^ 
         | 
         --- fails as styleFns[type] yields undefined which is not a function 

にunexpetedキー

scope.computeStyle = (component) -> 
    if component?.height? 
     height = component.height * 50 
    return DashboardLayoutStyleCalculator.computeStyleFor(component.element.type, height) 
                  ^^^^^^^^^^^^^^^^^^^^^^ 
                   | 
                   ---- Not what you expect 

したがって、あなたの後の呼び出しを生成することを前提とするものの表現typestyleFns[type]歩留まりを確認するために、いくつかの出力を追加します表示されるものと

答えて

関連する問題