Can anyone help me figure out how to utilize a string as a variable within the scope in my code? Here's what I have:
In my HTML (where type1 can be type2, type3, and more):
<div style="color:red;font-size:11px;">{{ error.type1 }}</div>
And here is part of my controller:
$scope.validate = function(string, value){
// let's say string = type1
if (value != 'answer'){
$scope.error.string = 'Incorrect, try again';
}
}
My question is, how do I dynamically set $scope.error.type1 = 'Incorrect'
? I have multiple errors displayed on a form above each input field, and the validate function checks when a value is entered. I want to avoid writing numerous conditionals based on the string value. Any suggestions on how to achieve this dynamically?