我试图使用元素属性将数据从控制器传递到隔离的范围.这是我在视图中的标记:
<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 =“”.
有人可以解释我错过了什么吗?