1

I am using ng-bing-html to show content in html.

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

In JS part:

$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>'

In js lvldraggable is an attribute defined in the directive:

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")
]

But in the front end, lvldraggable attribute cannot be detected and translated in html. How should I fix that?

Thanks in advance!

8
  • Yes, this is correct, ng-bind-html will not recognize directives. It is for static html. If you search SO, there are plenty of questions about this. Here is one Commented May 4, 2014 at 9:43
  • @DavinTryon Hi, thanks, so how should I resolve this problem Commented May 4, 2014 at 9:45
  • This is a good start: stackoverflow.com/questions/21723305/… Commented May 4, 2014 at 9:46
  • possible duplicate of angular ng-bind-html-unsafe and directive within it Commented May 4, 2014 at 9:47
  • @DavinTryon thanks, so I should add compile in directive or in the showComponent? Commented May 4, 2014 at 9:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.