Is it possible to dynamically inject JavaScript code that is stored in a string into AngularJS controllers?
var dynamicJS = "function DoSomething(value){var x = 1+1 return 2;}"
I need to inject the above function dynamically into my AngularJS controller and have it executed when there is a selection change in a drop-down menu. The values in the drop-down are bound to the AngularJS controller. Each row of data may require a different JavaScript function, which is determined by application configuration. While I am aware of using $eval
, I am looking for better approaches if they exist.
Does anyone have any suggestions or ideas on how to achieve this?
Note: Using AngularJS v1.4.5