Is there a way to add JavaScript code stored in a string in AngularJS controllers dynamically?
var dynamicJS = "function DoSomething(value){var x = 1+1 return 2;}"
I need to dynamically inject the above function into my AngularJS controller and call it when I change the selection of the drop-down list whose values are bound to the AngularJS controller. The reason is that the JavaScript function will vary depending on my every row of data that I based on my configuration at the application level. I know what we can use $eval, but would like to get some better approaches if they exist.
Can anyone give me any idea on this?
Note. I am using AngularJS v1.4.5
source
share