[英]ng-if not working, but ng-show works
我試圖用Angular js在列表中顯示項目。 我希望使用以下代碼將項目連續組織為3個項目:
<div class='row-fluid' ng-repeat="region in regions" ng-show="$index % 3 == 0">
<span class='span4 checkbox'>
<input type="checkbox" ng-model="regions[$index].checked" ng-hide='regions[$index].text == null'> {{regions[$index].text}}
</span>
<span class='span4 checkbox'>
<input type="checkbox" ng-model="regions[$index+1].checked" ng-hide='regions[$index+1].text == null'> {{regions[$index+1].text}}
</span>
<span class='span4 checkbox'>
<input type="checkbox" ng-model="regions[$index+2].checked" ng-hide='regions[$index+2].text == null'> {{regions[$index+2].text}}
</span>
</div>
如果使用“ ng-show”時工作正常。 但是當我用'ng-if'切換時,它根本不起作用。 (它顯示所有“區域”,並且不使用$ index%3 == 0進行過濾)。 我當時以為“ ng-if”應該是實現我的布局設計的一種更標准的方法,但不知道為什么它根本不起作用。
以下是無效的代碼:
<div class='row-fluid' ng-repeat="region in regions" ng-if="$index % 3 == 0">
<span class='span4 checkbox'>
<input type="checkbox" ng-model="regions[$index].checked" ng-hide='regions[$index].text == null'> {{regions[$index].text}}
</span>
<span class='span4 checkbox'>
<input type="checkbox" ng-model="regions[$index+1].checked" ng-hide='regions[$index+1].text == null'> {{regions[$index+1].text}}
</span>
<span class='span4 checkbox'>
<input type="checkbox" ng-model="regions[$index+2].checked" ng-hide='regions[$index+2].text == null'> {{regions[$index+2].text}}
</span>
</div>
你能幫我嗎?
有人正在嘗試尋找答案...嘗試在與ng-if結合使用時先將$ index(或與ng-if結合使用時遇到問題的任何變量)聲明到控制器中。 否則,ng-if可能會創建自己的范圍。 有關更多信息,請訪問關於stackoverflow的此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.