ng-style 和 ng-disabled 最初评估为真,即使布尔值在 ng-repeat 中为假?
ng-style and ng-disabled initially evaluate as true even though boolean is false in ng-repeat?
我 运行 在 ng-repeat
的上下文中遇到 ng-style
和 ng-disabled
的奇怪问题。我有以下模板...
<li ng-repeat="value in currentFacet.values track by $index">
{{ showAll }}
<input type="checkbox" ng-model="options[$index]" ng-true-value="'{{ value.label }}'" ng-checked="value.isActive" ng-disabled="showAll"/>
<span ng-style="showAll ? {color:'gray'} : {}">{{ value.label }}</span>
</li>
这会生成一个复选框列表。有一个 showAll
布尔值可以禁用所有这些复选框。
最初,当页面加载时,ng-style
和 ng-disabled
的计算结果好像布尔值是真的...即使当我查看布尔值的当前状态时(这就是为什么{{ showAll }}
在那里)这是错误的。
如果我将布尔值更改为 true,然后再更改为 false,功能将按预期运行。只有在初始页面加载时才会发生这种意外行为。
检查一次 showAll 的类型,我假设最初它是字符串。这就是为什么条件在负载下工作正常。如果('false')为真。
我 运行 在 ng-repeat
的上下文中遇到 ng-style
和 ng-disabled
的奇怪问题。我有以下模板...
<li ng-repeat="value in currentFacet.values track by $index">
{{ showAll }}
<input type="checkbox" ng-model="options[$index]" ng-true-value="'{{ value.label }}'" ng-checked="value.isActive" ng-disabled="showAll"/>
<span ng-style="showAll ? {color:'gray'} : {}">{{ value.label }}</span>
</li>
这会生成一个复选框列表。有一个 showAll
布尔值可以禁用所有这些复选框。
最初,当页面加载时,ng-style
和 ng-disabled
的计算结果好像布尔值是真的...即使当我查看布尔值的当前状态时(这就是为什么{{ showAll }}
在那里)这是错误的。
如果我将布尔值更改为 true,然后再更改为 false,功能将按预期运行。只有在初始页面加载时才会发生这种意外行为。
检查一次 showAll 的类型,我假设最初它是字符串。这就是为什么条件在负载下工作正常。如果('false')为真。