In the code below I am compiling a directive that includes an expression for ng-required. As long as the expression is true or false, all is well, however when ng-required="appConfig.requireBirthdate", the eval is failing. So, I must be doing something wrong. How do I get the true false value for the ng-required expression while in the context of compiling a directive?
The last line of the code is where I'm having trouble, and that problem is with the eval() eval is not happening in the context of the scope where that expression would be defined.
return {
restrict: 'E',
priority: 102, // We need this directive to happen before ng-model and the boolean directives
terminal: true, // We are going to deal with this element
compile: function(element, attrs) {
if ( attrs.ngRepeat || attrs.ngSwitch || attrs.uiIf ) {
throw new Error('The ng-repeat, ng-switch and ui-if directives are not supported on the same element as the field directive.');
}
if ( !attrs.ngModel ) {
throw new Error('The ng-model directive must appear on the field element');
}
// Extract the label and validation message info from the directive's original element
var validationMessages = getValidationMessageMap(element);
var labelContent = getLabelContent(element, eval(attrs['ngRequired']));