I'm currently working on a project that involves displaying and hiding a lot of content dynamically using ng-show
. Some of the expressions being evaluated are quite lengthy, like this...
<div
ng-show="some.object.with.nested.values
&& some.other.object.with.other.nested.values
&& also.looking.at.the.value.in.this.object
&& !obj.example.something.goes.here"
>...</div>
My goal is to ensure that this content is ADA WCAG 2.0 compliant. As part of this effort, I am adding aria-disabled
attributes to all the hidden content. The aria-disabled
attribute will have a value of either true
or false
, reflecting whether the content is hidden (true
) or visible (
false>). It should always be the opposite of the <code>ng-show
value and update dynamically as the ng-show
attribute changes.
To maintain code cleanliness and readability, I want to avoid duplicating code and inverting each value manually with an exclamation mark, like this...
<div
ng-show="some.object.with.nested.values
&& some.other.object.with.other.nested.values
&& also.looking.at.the.value.in.this.object
&& !obj.example.something.goes.here"
aria-disabled="!some.object.with.nested.values
&& !some.other.object.with.other.nested.values
&& !also.looking.at.the.value.in.this.object
&& obj.example.something.goes.here"
>...</div>
I would prefer to utilize a method like this...
<div
ng-show="some.object.with.nested.values
&& some.other.object.with.other.nested.values
&& also.looking.at.the.value.in.this.object
&& !obj.example.something.goes.here"
aria-disabled="{{invertNgShow(this)}}"
>...</div>
The concept here is to use a custom function called invertNgShow
to retrieve the Boolean value of the element's ng-show
attribute, invert it, and return the result. However, I have not yet implemented a working solution for this.
Thank you for your assistance.