I am using angularjs and ng-include in in the view. I need to create a graphic using dygraph. I have 5 templates that show or hide when I click one button. When I click the button ng-include load a template. In this template, I have a div with Id where I want to show the graphic.
The problem is that this id doesn't exist in DOM when I click. If I click again, it shows the graphic without any problem because the Id exist.
My code:
View:
<button class="btn" ng-click="exploreLineChart()">Line chart</button>
<div ng-include="currentTemplate.url"></div>
Template:
<div id="linechart"></div>
Controller:
$scope.templates = [
{url: 'views/explore-dataset/summary.html', title: 'Summary'},
{url: 'views/explore-dataset/line-chart.html', title: 'Line Chart'},
{url: 'views/explore-dataset/bar-chart.html', title: 'Bar Chart'},
{url: 'views/explore-dataset/scatter.html', title: 'Scatter Plot'},
{url: 'views/explore-dataset/pie-chart.html', title: 'Pie Chart'},
{url: 'views/explore-dataset/correlation.html', title: 'Correlation'}
];
$scope.exploreLineChart = function ()
{
$scope.currentTemplate = $scope.templates[1];
linechart = new Dygraph(document.getElementById("linechart"),
$scope.csvContent,
{
height: 320
});
}
I advice you to create a directive to manage better the scope and graph state, for example:
Directive:
Html: