How to access ng-model from attribute directive?
<p>I'm trying to write a custom directive to validate input value: does it belong to the specified range. The problem is that I can't access <code>ng-model</code> without knowing the name of the scope variable which is used for <code>ng-model</code>. Considering that directive has to be reused with different inputs I want to access <code>ng-model</code> directly. I did try to use <code>scope[attrs.ngModel]</code> but got the <code>undefined</code> value. How can read <code>ng-model</code> value inside directive? Thank you.</p>

<pre><code>netupApp.directive('between', function() {
return {
    restrict: 'A',
    require: 'ngModel',
    link: function(scope, element, attrs, ngModelCtrl) {
        scope.$watch('dataSubmitting', function(dataSubmitting){
            if (dataSubmitting) {
                var min = Number(attrs.min);
                var max = Number(attrs.max);
                console.log(attrs.ngModel); // "number"
                console.log(scope[attrs.ngModel]); // undefined
                var inputText = scope.number; // that is the var used in ng-model
                console.log(min); // 10
                console.log(inputText); // would be the input value
                console.log(max); //20
                if (inputText &lt;= min || inputText &gt;= max) {
                    scope.alerts.push({
                        msg: 'error',
                        type: 'danger',
                        icon: 'warning',
                        'closable': true
                    });
                }
            }
        });
    }
};
});
</code></pre>