Javascript ng如果不起作用,但ng show起作用
我试图用角js显示列表中的项目。我希望用以下代码将3个项目组织成一行:Javascript ng如果不起作用,但ng show起作用,javascript,angularjs,Javascript,Angularjs,我试图用角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='reg
<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>
{{regions[$index].text}
{{regions[$index+1].text}
{{regions[$index+2].text}
当我使用“ng show”时,If工作正常。但当我把它换成“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>
{{regions[$index].text}
{{regions[$index+1].text}
{{regions[$index+2].text}
您能帮我一下吗?现在正试图找到答案的人……尝试在将$index(或您在使用ng if时遇到问题的任何变量)与ng if一起使用时,先将其声明到控制器中。如果没有这一点,ng if可能会创建自己的范围。有关更多信息,请访问有关stackoverflow的问题
现在正试图找到答案的人…尝试在与ng if一起使用时,首先将$index(或与ng if一起使用时遇到问题的任何变量)声明到控制器中。如果没有这一点,ng if可能会创建自己的范围。有关更多信息,请访问有关stackoverflow的问题
请显示不起作用的代码。查看工作代码没有用。哪里没有工作代码?除了上述问题外,还需要检查ng if和ng show/hide之间的差异。有很强的理由选择什么@Juhana,我添加了无效代码。唯一的区别是我使用的是ng if还是ng show您是否尝试使用ng if=“$index%3=='0'”
ng if
阻止html进入DOM-如果html不存在,您的$index
不会按您认为的方式递增(至少我是这么认为的-解释了与ngShow
到ngIf
的区别。请显示不起作用的代码。查看起作用的代码是没有用的。哪里没有起作用的代码?除了上面提到的问题外,检查ng if和ng show/hide之间的区别是值得的。有很强的理由选择什么@Juhana,我添加了不起作用的代码。唯一的区别是我使用的是ng if还是ng SHOW。您是否尝试使用ng if=“$index%3=='0'”ng if
阻止html进入DOM-如果html不存在,您的$index
将不会以您认为的方式递增(至少我是这么想的-解释了ngShow
与ngIf