0

I am having trying to show content of a <div id="right"> when a mouse is hovered on another div. #right contains a graph from Angular-charts (http://jtblin.github.io/angular-chart.js/).

Here is my jQuery:

                    <div>
                       <div>
                          <canvas id="doughnut" class="chart chart-doughnut" data="data" labels="labels" legend="true" click="onClick">
                          </canvas>
                       </div>
                       <h3>Some text</h3>
                    </div>

I tried implementing this to show in #right when hovered over my other div in my jQuery.

 $(function(){

          $('#some_other_div').on('mouseover', function(){
            $('#right').html('<div><canvas id="doughnut" class="chart chart-doughnut" data="data" labels="labels" legend="true" click="onClick"></canvas></div><h3>Some text</h3>');
            })     
    });

When hovering on some_other_div, Only a blank space and Some text shows at the bottom. I made sure the graph works elsewhere when implementing it directly in HTML. Only facing this problem through .html.

Is there a way to fix this? Thank you.

1 Answers1

0

Changing the html outside the Angular system doesn't tell Angular that the DOM is changed for it to act. Try doing the change via $apply() function.

angular.element("#some_other_div").scope().$apply($('#right').html('<div><canvas id="doughnut" class="chart chart-doughnut" data="data" labels="labels" legend="true" click="onClick"></canvas></div><h3>Some text</h3>');)
Charlie
  • 22,886
  • 11
  • 59
  • 90