ps0604 ps0604 - 1 month ago 17
AngularJS Question

Dynamically creating mutiple Highcharts charts in Angular directive

In my directive template I have

<div id="chartdiv-{{name}}" style="width:100%;height:100%"></div>


where name is variable and assigned to each directive when it is created.

The chart is created with

$('#chartdiv-'+scope.name).highcharts(settings);


But this doesn't work. Everything works fine if I don't use the
name
variable. Any ideas?

Answer

Change it like this,

<div id="{{ 'chartdiv-' + name }}"></div>

EDIT

If you are creating template inside a directive, it should be

<div id="chartdiv-{{$scope.name}}"></div>
Comments