angular-chart.js icon indicating copy to clipboard operation
angular-chart.js copied to clipboard

Problem when using <canvas .....> as the template of new directive.

Open flexdeviser opened this issue 8 years ago • 6 comments

problem as the title. please check jsBin https://jsbin.com/tuziwi/edit?html,css,js,console,output

flexdeviser avatar Mar 22 '16 10:03 flexdeviser

Hey, not sure what you're trying to do here but it isn't supported. You should read the doc on how to use the library: http://jtblin.github.io/angular-chart.js/

jtblin avatar Mar 22 '16 18:03 jtblin

Did you check my jsBin code? I have tow directives in my javascript file. The difference between these tow directives is the content of "template". If I want to show the chart by using my own directive, I have to use your "angular-chart.js" directive as a child of "DIV". The bad things will happen If the canvas has no parent. .directive('pie', function () { return { restrict: 'E', scope: {}, template: function (element, attrs) { //<div>your directive</div> return '<div><canvas class="chart chart-pie" chart-data="piedatas" chart-labels="pielabels" chart-options="pieoptions"></canvas></div>'; }, controller: function ($scope) { $scope.pielabels = ['A', 'V']; $scope.piedatas = [30, 4]; $scope.pieoptions = {legend: {display: true}}; } } });

flexdeviser avatar Mar 22 '16 22:03 flexdeviser

Apologies, I didn't look at it properly. Just got out of a red eye flight this morning and I totally got it wrong...

Would you want to try out with the 2.0 branch? I wonder if it's because the current version adds a div wrapper around the canvas.

jtblin avatar Mar 22 '16 23:03 jtblin

I confirmed this is happening on the 2.x branch. You have to wrap the canvas in a container, otherwise you get a "multiple new/isolate scopes on same directive" error.

carlosrymer avatar Jul 10 '16 16:07 carlosrymer

@flexdeviser: I met the same problem. It's gone when I set width and height for the canvas or parent element

lvt1325 avatar Aug 18 '16 08:08 lvt1325

Also this problem appears when you try to do use canvas as the only element of angular component. Making canvas a child of another element resolves it.

volodymyrlut avatar Feb 12 '17 23:02 volodymyrlut