Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9224019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:12:49+00:00 2026-06-18T04:12:49+00:00

So I am building a table dynamically, roughtly like this <tbody ng-repeat=d in data>

  • 0

So I am building a table dynamically, roughtly like this

<tbody ng-repeat="d in data">
<td>{{d.name}}</td>
<td>{{d.dircleColor}}</td>   
<td id="a{{d.index}}>{{d.someOtherData}}</td>
...

“data” is an array, $scope.data in the Controller. Basic Angular, works very well.

Now, I also have to add a svg element (D3.js) into one of those dynamically generated <td></td>s

These have to correspond to the visualization that is also based on $scope.data, so that the red circle in the graph corresponds to the red circle in the table, and the user knows where to look for the information.

My biggest hope is a directive

.directive('dirCircle', function () {
   return function ($scope, elm, attrs) {                        
     var vis = d3.select(elm[0]).append("svg").attr("width", w).
        attr("height", h).attr("class", "circlesClass");
     node.append("svg:text")    [... more styling...]

This works, but at the moment I don’t know how to tell the directive, which color my little svg-circle element should have. This information is in the $scope.data – array. But just accessing the $scope would not be enough. I need the information of the “current” element as it is drawn. Is that possible?


If this is not possible, here are some possible workarounds:

1) If the directive could become “self-aware” and look around the DOM in which it was put, that could help. Notice in my above code I have <td id="a{{d.index}}>...

The “a” is just there because ids start with a letter. d.index identifies the relevant data in my array, so if I can access $scope.data from my directive…?

2) generating D3 like you would normally, but putting it into the dynamically generated table cells like so:

for (var i = 0; i < _data.length; i++) {
var svgContainer = d3.select("#a" + _data[i].index).append("svg")  //circleData[0].ci
            .attr("width", 20)
            .attr("height", 20)
            .attr("class", "circlesOnTheRight");

works, however, the “compilation” from the “html-template” (the ng-repeat/{{…}} – stuff) always comes at the end. If new elements are added to the array, my function would always fire before angular creates the new table cells. When I tried it, even $scope.$on(‘includeContentLoaded’, alert(“…”)); fires before angular is done.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:12:50+00:00Added an answer on June 18, 2026 at 4:12 am

    I don’t know how to tell the directive, which color my little svg-circle element should have. This information is in the $scope.data

    Pass the color as an attribute on the same element where your directive will be used (wherever that is):

    <some_element dir-circle the-color="d.color??"></some_element>
    

    Then in your directive:

    return function ($scope, elm, attrs) { 
       // $scope.$eval(attrs.theColor) contains your color
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building some <table> data dynamically using jQuery, but I'm getting the following error:
I am building a html table dynamically with Javascript; This is my html table:
I have a stream of JSON coming back and am building a table dynamically
I'm building a table cell using two bound ember.js views on data. When I
I'm dynamically building a .NET Table, including TableRows with TablesSection set, resulting in 1
I'm dynamically building html table from c# code. Here is a portion of my
Context: Building an app that populates a table that takes in data from a
I'm building a html table dynamically in an ASP.NET code behind file using C#.
i am dynamically building a page. This page needs to read information from input
I building an app dictionary, in this app data of dictionary is json and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.