I have the following Javascript variable:
scope.model = {
  errors: {
    email: ["error1", "error2"],
    name: ["error"]
  }
}
And I have a function as follows:
function (scope, element, attributes) {            
  if (scope.model.errors) {
    if (scope.model.errors[attributes.validator]) 
      // Do something
}
The problem is that the errors are not always on the same scope variable.
I can have something like:
scope.view = {
  newErrors: {
    email: ["error1", "error2"],
    name: ["error"]
  }
Inside the function I know how to get the variable where they are:
function (scope, element, attributes) {            
  var errors = attributes["validatorErrors"];
  // Note: errors is this case "view.newErrors"
  // So the following code would become: 
  if (scope.view.newErrors) {
    if (scope.view.newErrors[attributes.validator]) 
      // Do something
}
UPDATE
I have tried [] before but now I understand why it was not working:
function (scope, element, attributes) {            
  var errors = attributes["validatorErrors"];
  if (scope[errors]) {
    if (scope.[errors][attributes.validator]) 
      // Do something
}
If errors = 'errors' it will work ...
If errors = 'model.errors' it won't. In this case I would need:
scope['model']['errors'] ...
How can I solve this?
 
     
    