I'm building a chartist Directive for my AngularJS app. What breaks my understanding at the moment is how I integrate jQuery code the Angular way.
This framework is using jQuery for creating a tooltip. The code is right here:
var $chart = $('.ct-chart'); var $toolTip = $chart .append('<div class="tooltip"></div>') .find('.tooltip') .hide(); $chart.on('mouseenter', '.ct-point', function() { var $point = $(this); var value = $point.attr('ct:value'); $toolTip.html(value).show(); }); $chart.on('mouseleave', '.ct-point', function() { $toolTip.hide(); }); $chart.on('mousemove', function(event) { $toolTip.css({ left: (event.offsetX || event.originalEvent.layerX) - $toolTip.width() / 2 - 10, top: (event.offsetY || event.originalEvent.layerY) - $toolTip.height() - 40 }); }); My question is: How should I translate this to an AngularJS way of doing things?
- I'm getting an element from the DOM
- Adding a new element to it
- And then have interactions with this newly added element
What would be the way Angular is handling those things? Is a 1:1 "translation" approbate or should I put ngHide, ngMouseenter inside the view?
var $chart = $('.ct-chart');rather than getting elements like this, you get $element directly in your directives. so its kinda angularjs finds the element for you and give you its handle...