0

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>
3
  • 1
    I'd suggest using an Angular wrapped version of AmCharts that supports async data/promises. Here's an example Commented Jan 20, 2017 at 16:05
  • What do you mean before the service return ? Commented Jan 20, 2017 at 16:34
  • 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. Commented Jan 20, 2017 at 16:37

1 Answer 1

0

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']);
});
Sign up to request clarification or add additional context in comments.

4 Comments

I can not remove the ng-app because there are other features that use it.
@TiagoJavaman you can try to add the attribute in javascript $('#item').attr('ng-app', 'app'); maybe that will work.
What would be #item ? Do you have an example?
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.