How to use a string as a variable within the scope. Heres my code:
HTML (one of many divs like this where type1 can be type2, type3, and so on):
<div style="color:red;font-size:11px;">{{ error.type1 }}</div>
controller:
$scope.validate = function(string, value){
// lets say string = type1
if (value != 'answer'){
$scope.error.string = 'Incorrect, try again';
}
}
How can I run $scope.error.type1 = 'Incorrect'
? I have many different errors on a form above each input field and the validate
function is called when a value is entered. My goal is to avoid writing a TON of conditionals based on what the string is equal too. How can I use this dynamically?
$scope.error.type1
instead of$scope.error.string
in your example? Also if you could give more examples of what your different errors look like, that would be helpful.