I have a web app that combines Angularjs and d3js. One of my directives called dailyView
sets up a tooltip using a function drawtooltip()
defined in a service called cfg
. The directive code is similar to the following:
app.directive('dailyView', ['cfg', function (cfg) {
return {
restrict: 'E',
link: function(scope, element, attrs) {
scope.$watch('daily', function(newVal, oldVal) {
if (!newVal) return;
cfg.drawDaily(scope.daily[attrs.bus], element, attrs.bus);
$('#sortable2').sortable({
start: scope.dragStart,
update: scope.dragEnd
});
cfg.drawTooltip();
});
}
};
}]);
On the other hand, the drawTooltip()
function is defined like:
app.factory('cfg', ['$window', '$rootScope', '$cookieStore', function($window, $rootScope, $cookieStore){
function drawTooltip(){
var tooltip = d3.select(".tooltip");
d3.selectAll(".myImage")
.on("mousemove", function(d){
tooltip.transition().duration(100)
.style("opacity", .9);
tooltip.html('<p>{{"' + d.measure + '"|myLocationFilter}}</p>')
.style("left", (d3.event.pageX + 20) + "px")
.style("top", (d3.event.pageY - 110) + "px");
})
.on("mouseout", function(d) {
tooltip.transition().duration(200)
.style("opacity", 0);
});
}
My angular filter should transform the d.measure
string into a descriptive text that changes based on the browser language. The problem is that my the filter is not recognized and my tooltip simply shows the following text (e.g. when the measure data bound to the element is the string "plug": {{"plug"|myLocationFilter}}.
How can I inject my angular filter into the d3js html element?
Note: This is a fairly similar question that has not been answered yet.
Edit 1: I've tried using $compile()(scope) in the directive, right after calling
cfg.drawtooltip()
but the angular filter did not work.Edit 2: After testing the multiple suggestions offered in the comments, it is clear that the problem lies in the use of the
html()
method of a d3 selection. Would it be possible to somehow wait until$compile()
is processed and then use the outerHTML value of the resulting object?