我正在开发一个项目,其中包含大量使用动态显示/隐藏的内容ng-show。一些被评估的表达式是冗长的。像这样的东西...
<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>
我需要使此内容符合 ADA WCAG 2.0。作为这项工作的一部分,我正在aria-disabled为所有隐藏内容添加属性。该aria-disabled属性将有一个true或false值。因此,如果内容隐藏,则aria-disabled属性将为true,如果内容可见,则属性将为false。换句话说,它总是ng-show值的倒数,它需要随着ng-show属性值的变化而动态更新。
出于明显的原因(例如可维护性、可读性、减少膨胀等),我想避免重复代码并用爆炸来反转每个值,就像这样......
<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>
我宁愿做这样的事情......
<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>
这个想法是使用自定义invertNgShow函数来获取元素ng-show属性的布尔值,反转值并返回。不用说,我还没有一个可行的解决方案。
提前致谢。