【发布时间】:2014-06-12 02:40:40
【问题描述】:
我是 angularjs 的新手。我正在使用angular-xeditable。我的视图中有可选字段。选择字段的默认值有问题(最后选择)。
这工作没有错误,但不正确
class MyCtrl
constructor: ($scope, @$filter, @$log) ->
actions=[]
showActions: (action) ->
selected = []
if action then selected = $filter('filter')(@actions, {name: action})
if selected.length then return selected[0].name else return "Not set"
controllersModule.controller 'MyCtrl', MyCtrl
如果我使用$filter 而不使用@,则会出现错误:
class MyCtrl
constructor: ($scope, $filter, @$log) ->
actions=[]
showActions: (action) ->
selected = []
if action then selected = $filter('filter')(@actions, {name: action})
if selected.length then return selected[0].name else return "Not set"
controllersModule.controller 'MyCtrl', MyCtrl
错误:[$interpolate:interr] 无法插值: {{ mc.showActions(flow.action)}}
ReferenceError: $filter 未定义
我的问题是:
- angularjs 中 @$ 和 $ 有什么区别
- 为什么在我的情况下没有按预期工作?
我的 html 中的一段代码
<div ng-controller="MyCtrl as mc">
...
<td>
<span editable-select="flow.action" e-name="action" onshow="mc.getActions()"
e-ng-options="action.id as action.name for action in mc.actions"
e-form="rowform" e-required>
{{ mc.showActions(flow.action)}}
</span>
</td>
...
</div>
提前致谢。
【问题讨论】:
-
现在,仅在代码示例中的选项卡就会导致问题。
showActions将位于一个单独的对象上,而不是 MyCtrl 的一部分。
标签: angularjs coffeescript x-editable