2016-06-09 22 views
0

Ich habe Scale dynamisch mit der Eval-Funktion in D3 erstellt, aber wenn ich d3 mit eckigen verwendet, funktionierte die Eval-Funktion nicht richtig und durch Fehler, während ich die Skala anrief.Angular mit D3 js

TypeError: e.copy is not a function 
    at SVGGElement.<anonymous> (http://localhost:3000/app/d3.v3.min.js:5:13917) 
    at http://localhost:3000/app/d3.v3.min.js:3:15103 
    at Y (http://localhost:3000/app/d3.v3.min.js:1:4505) 
    at Array.Co.each (http://localhost:3000/app/d3.v3.min.js:3:15078) 
    at Array.n (http://localhost:3000/app/d3.v3.min.js:5:13838) 
    at Array.Co.call (http://localhost:3000/app/d3.v3.min.js:3:15178) 
    at Scope.HistoricalGraph.$scope.draw (http://localhost:3000/app/beanstalk/yhgraph/historicalgraph/historicalgraph.controller.js:418:26) 
    at fn (eval at <anonymous> `enter code here`(http://localhost:3000/bower_components/angular/angular.js:14432:15), <anonymous>:2:203) 
    at expensiveCheckFn (http://localhost:3000/bower_components/angular/angular.js:15485:18) 
    at ngEventDirectives.(anonymous function).compile.element.on.callback (http://localhost:3000/bower_components/angular/angular.js:25018:17) 
+1

'eval' ist böse versuchen, es zu vermeiden. Stellen Sie einige Code in Frage – murli2308

+0

, aber wie man Variable dynamisch in angular js .. ich meine zu sagen, dass angenommen, ich habe 3 Kanal wie var channel = ["x", "y", "z"]; also ich möchte 3 Variable dynamisch deklarieren und einen Wert zuweisen. wie kann ich tun var x = einige vale var y = ein wenig wert wenn ich eval funktion in normalen js dann wird es in ordnung sein aber in eckigen wird es einige fehler geben – Sujit

Antwort

0

Sie können ein dynamisches Objekt wie erstellen:

var channelsObject = {}; 
for(var i = 0;i <channel.length; i++){ 
    channelsObject[channel[i]] = {}; 
} 

diese Weise können Sie Objekt wie folgt erhalten:

{ 
    x:{}, 
    y:{}, 
    z:{} 
} 

Man sollte mit eval immer vermeiden.