0

So I have this script tag that I want to add into my angular project:

<script>
 var data = [4, 8, 15, 16, 23, 42];

 var x = d3.scale.linear()
   .domain([0, d3.max(data)])
   .range([0, 420]);

 d3.select(".chart")
   .selectAll("div")
     .data(data)
   .enter().append("div")
     .style("width", function(d) { return x(d) + "px"; })
     .text(function(d) { return d; });
  </script>

I've been trying to figure out what the best way to add this snippet into my angularjs app. I saw this here: render <script> tag in angularjs but this question was asked a while ago, so I wanted to see if there was a better (newer) way to accomplish this. I initially added it to my view but i'm not able to pass any data from my controller into the block. For example, I wanna do something like:

 var data = {{someArray}}; 

But i end up getting an error:

 SyntaxError: Unexpected token {

I'm trying to figure out the best approach to this. Would it be best to just follow the example in the link above? Let me know what you all think, thanks!

3
  • 2
    This is not correct. refer to this article. this might help you. sitepoint.com/… Commented Sep 12, 2015 at 5:41
  • You can't do that, use a directive Commented Sep 12, 2015 at 8:05
  • Thanks @micronyks that's exactly what I needed. Commented Sep 12, 2015 at 19:18

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.