【发布时间】:2017-01-19 18:03:00
【问题描述】:
我有一个名为DashboardLayoutStyleCalculatorService 的服务,使用以下方法。其他方法已删除,因为它们与问题并不真正相关:
styleFns =
table: @computeStyleForTable
single_value: @computeStyleForSingleValue
@computeStyleFor = (type, height = null) ->
return styleFns[type](height)
通过两个不同的指令调用此服务:
指令 1:
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?)
简而言之,我的代码所做的是,根据computeStyleFor 中的输入类型,它为表格或单值可视化调用两种不同的方法。还有一些基于某些参数的动态高度计算,这些参数对于这个问题并不完全必要。
当我在浏览器中运行此代码时,我收到以下错误:
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 似乎存在问题。
【问题讨论】:
标签: javascript angularjs service coffeescript directive