0

I am working on a web app using angular meteor and writing JS in ECMAscript 6 class style. I need to append an element, that will later be clicked on, to an existing div dynamically.

The problem I am having is that when I append the element, the angular ng-mouseover directive contained within the appended element's html disappears and does not work.

I want the newly appended element to listen for hover events, and the only solution I have found for doing so is to somehow use $compile. However, I am extremely new to Angular and struggled to understand the $compile documentation, especially when trying to convert it into ECMAscript acceptable syntax. Can anyone help me do this correctly?

My attempt at appending the element via JQuery:

$('#progress-container').append("<img src='greenpin.png' ng-click='chat.hovering($event)' id='" + pinId + "' class='pin' style='left: " + pos + "%'/>");
2

1 Answer 1

1

Using $compile would do the trick!

$('body').append($compile("<my-angular-directive />")(scope));
scope.$apply();
Sign up to request clarification or add additional context in comments.

Comments

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.