【发布时间】:2014-04-13 13:33:18
【问题描述】:
我正在尝试使用元素属性将数据从控制器传递到隔离范围。这是我在视图中的标签:
<comment ng-attr-cid="{{question.id}}" ctype="questions"></div>
这是指令:
'use strict'
angular.module('arlo.directives').directive "comment", ['Comment', (Comment) ->
directive =
templateUrl: "angular/partials/comment.html"
restrict: "E"
scope:
cid: "="
ctype: "="
link: (scope, element, attrs) ->
scope.toggled = false
scope.comment = null
scope.comments
scope.toggle = ->
if scope.toggled is true then scope.toggled = false else scope.toggled = true
scope.comment = null
scope.addComment = ->
Comment.addComment(scope.ctype, scope.cid, scope.comment).then ->
scope.comments = Comments.commentsList
scope.toggled = false
scope.comment = null
scope.loadComments = ->
Comment.loadComments(scope.ctype, scope.cid).then ->
scope.comments = Comments.commentsList
scope.loadComments()
]
问题是 cid 被分配了“{{question.id}}”而不是 question.id 的值。我尝试使用 ng-attr-cid="question.id" 但这也不起作用。最重要的是,ctype 被评估为未定义。
如果我在任何其他元素上添加 ng-attr-cid,它会评估并将 cid="" 添加到元素。
有人可以解释一下我缺少什么吗?
【问题讨论】: