There is a directive that may or may not be required, and it can be used in two different ways.
<my-foo required></my-foo>
or
<my-foo ng-required="data.value > 10"></my-foo>
Even though require
and ngRequire
are essentially the same thing, you would expect the directive to work like this
HTML:
<my-foo ng-require="data.isRequired"></my-foo>
JS:
...
.directive('myFoo', function () {
return {
restrict: 'E',
scope: {
required: '='
}
...
However, this approach does not work as expected because scope.require
is undefined
. To resolve this issue, the scope definition needs to be modified to
scope: {
required: '=ngRequired'
}
So, the question arises: what is the best way to handle both situations so that the value is stored in scope.required
? Should both definitions be included or should attrs be used from the link function?