Executing javascript functions stored as string using AngularJS -


is there way inject javascript code stored in string in angularjs controllers dynamically?

var dynamicjs = "function dosomething(value){var x = 1+1  return 2;}" 

i have dynamically inject above function angularjs controller , have called on selection change of drop-down, values of bound angularjs controller. reason javascript function vary based on each row of data have based on configuration @ application level. aware can make use of $eval better approaches, if exist.

can give me idea on this?

note: using angularjs v1.4.5

i believe easier way parse string , use function constructor.

something this:

var dosomething = new function('value', 'var x = 1+1  return 2'); 

Comments