我試圖使用元素屬性將數據從控制器傳遞到隔離的作用域。下面是我的看法標籤: ng-attr不對指令元素進行評估
<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 =「」的元素。
能有人請解釋我缺少的是什麼?