I created html template inside a function and added a button in it. The reason I am doing so is because I want this template to popup when I click on the data node in a scatterplot created using d3.js v3. So when i click on the data point, the input box should popup with the information about the data point and a textarea where I can add additional text. But angular directives such as ng-click and ng-model won't fire when used on that button. Am I missing something or my way of doing it is wrong ?
vm.addAnnotateBox = function(event) {
var annotateText = "<div class='annotateBox'>" + "<h5 style='font-size: 22px;color:#fff; white-space:normal;'>";
annotateText = annotateText + "<h6 style='color:#dae1e1'>";
annotateText = annotateText + event.label + "</h5><small style='color:#dae1e1'>"; // jscs:disable maximumLineLength
annotateText = annotateText + event.time + "</small>";
annotateText = annotateText + "<div class='row'>";
annotateText = annotateText + "<textarea rows='3' cols='50' maxlength='100' style='color:black' ng-model='vm.annotateText' autofocus></textarea>";
annotateText = annotateText + "</div>";
annotateText = annotateText + "<button type='button' class='btn btn-primary pull-right' ng-click='d3.select(this.parentNode).remove()'>Done</button></div>";
return annotateText;
};
onclick works fine but not ng-click. Is it wrong to create a html template inside the controller ? I am calling the above function on click attribute of the data point:
eventGroup.select("circle")
.attr("class", "dot")
.attr("r", 4)
.attr("cx", 10)
.attr("cy", 10)
.attr("fill", function(d) { return d.evtColor ? d.evtColor : "#229ae5"; })
.attr("stroke", function(d) { return d.evtColor ? d.evtColor : "#229ae5"; })
.attr("stroke-width", 2)
.on("click", vm.addAnnotateBox());
The template appears on click currently but i am unable to save the text entered in the textarea using ng-model and on clicking the "Done" button, ng-click doesn't fire the desired function: