【发布时间】:2013-11-11 18:11:39
【问题描述】:
我无法让 $watch 向我返回一个 Javascript 对象。它总是我一个字符串,而不是像: "{'text':'你好'}"
这是我的指令(CoffeeScript):
app.directive 'progressIndicator', ->
restrict : 'E'
scope : { progress : '@' }
link : (scope,element,attrs) ->
scope.$watch 'progress' , (v) ->
scope.curPrg = v
template : '<label>In progress: {{curPrg.text}}' +
'<progress></progress>'
还有 HTML 代码:
<progress-indicator progress={'text':'Hello'}></progress-indicator>
我试过 attrs.$observe :同样的行为。
我尝试过控制器而不是链接:相同的行为。
怎么了?最好的方法是什么。 最后,我希望能够做到:
【问题讨论】:
-
编译后的(到 javascript 的)指令是什么样的?
-
来自 the documentation:
@或@attr- 将本地范围属性绑定到 DOM 属性的值。结果始终是字符串,因为 DOM 属性是字符串。 阅读其余文档。