angularjs - How to generate random div id inside Directive? -


i'm attempting render 2 charts using directive. chart requires unique target div render; however, appears directive generating single instance of control , not second. need pass id through parent scope instead? have tried implementation of id="graph_{{$id}}", doesn't work.

directive snippet: generate random number , assign target div tag

var num = math.floor((math.random() * 999999999) + 1);      return {         restrict: 'ae',  // e = element, = attribute, c = class, m = comment         replace: true,         scope: { //binds scope             val: '='         },         template: '<div id="graph_' + num + '"></div>',         link: function (scope, element, attrs) {           var dcpie = dc.piechart("#graph_" + num); 

html: add 2 instances of directive

<my-dc-graph val="graphpie"></my-dc-graph><br> <my-dc-graph val="graphpie2"></my-dc-graph> 

resulting html: 1 control renders, second remains empty same unique id

<div id="graph_432240223" val="graphpie" class="ng-isolate-scope dc-chart">... chart svg renders fine here ...</div> <div id="graph_432240223" val="graphpie2" class="ng-isolate-scope dc-chart">... nothing ...</div> 

math.random not truely random if call that, because based on timestamp. try , force miliseconds of time between math.random() ensure seeded different values, or make sure determine random number externally.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -