ng-bind-html无法将指令检测为属性

时间:2014-05-04 09:39:26

标签: javascript angularjs

我正在使用ng-bing-html来显示html中的内容。

<div ng-repeat="object in question">
   <div class="row">
      <div ng-bind-html="showComponent(object)"></div>
   </div>
</div>

在JS部分:

$scope.showComponent = (object) ->

        if typeof object.type == 'undefined'
            width = object.position[1]
            offset = object.position[2]

            content = object[$scope.lang]
            console.log(typeof content)
            return '<div lvldraggable="true"' + '>' + content + '</div>'

在js lvldraggable 是指令中定义的属性:

app.directive 'lvldraggable', ['$rootScope','uuid', ($rootScope, uuid)->
    restrict: 'A'
    replace: true
    link: (scope, el, attrs, controller) ->
        id = angular.element(el).attr("id")
        unless id
            id = uuid.new()
            angular.element(el).attr("id", id)

        el.bind "dragstart", (e)->
            e.originalEvent.dataTransfer.setData('text', id)
            $rootScope.$emit("LVL-DRAG-START")

        el.bind "dragend", (e)->
            $rootScope.$emit("LVL-DRAG-END")
]

但是在前端,lvldraggable属性无法在html中检测和翻译。 我该如何解决这个问题?

提前致谢!

0 个答案:

没有答案