Note: Similar to: angularjs execute expression from variable except I don't want to clutter up my scope with all the possibilities and data sets in use.
I want to be able to utilize pre-determined formulas in Angular's expressions.
Example:
var config = {
"Test": {
name: "test",
formula: true,
formulaValue: "item['propertyOne'] + item['propertyTwo']"
}
}
<div ng-repeat="item in myArray">
<span ng-if="config[item.name].formula">{{config[item.name].formulaValue}}</span>
</div>
Where the formula in formulaValue gets evaluated as if I typed it like:
<div ng-repeat="item in myArray">
<span>{{item['propertyOne'] + item['propertyTwo']}}</span>
</div>
How would I accomplish this? It's not quite feasible to make a $scope function for each type of formula either, as these are setup in a config in fairly large quantities.
eval()on that but due to security is always best to avoid eval. For concatenation a property that has just field names in array would be more ideal in the config