Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am trying to load a graph in AmCharts.

The problem is that the JavaScript script is loaded before I get the service return, it starts empty and I can not update the variable.

Any idea how to do this?

<script type="text/javascript">
    AmCharts.makeChart("chartdiv", {{json}} );
</script>
share|improve this question
1  
I'd suggest using an Angular wrapped version of AmCharts that supports async data/promises. Here's an example – Ankh yesterday
    
What do you mean before the service return ? – Korte yesterday
    
The html is loaded (javascript script) and then the variable json receives a json with the graphic to display. Basically I do not have the graph ready on loading the page. – Tiago Javaman yesterday

You can boostrap your angular application using javascript:

basically you remove your ng-app attribute and run this:

angular.element(function() {
  angular.bootstrap(document, ['myApp']);
});
share|improve this answer
    
I can not remove the ng-app because there are other features that use it. – Tiago Javaman yesterday
    
@TiagoJavaman you can try to add the attribute in javascript $('#item').attr('ng-app', 'app'); maybe that will work. – jcubic yesterday
    
What would be #item ? Do you have an example? – Tiago Javaman yesterday
    
@TiagoJavaman id of the element that should have the ng-app <div id="item" ng-app="app"> -> <div id="item"></div>, you can use other css selector like $('div:eq(0)').attr('ng-app', 'app'); for first div. – jcubic yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.