有条件的NG-包括angularjs [英] Conditional ng-include in angularjs
本文介绍了有条件的NG-包括angularjs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能做到有条件NG-包括angularJS?
例如我只希望包括的东西,如果,变量 X
设置为真正
。
< DIV NG-包括=/ partial.html>< / DIV>
解决方案
如果您使用的是V1.1.5角或更高版本,你也可以使用的 NG-如果:
< DIV NG-IF =XNG-包括=/ partial.html'>< / DIV>
如果您有任何旧版本:
使用 NG-开关:
<格上=X&GT NG-开关;
< DIV NG-开关时=真正的NG-包括=/ partial.html'>< / DIV>
< / DIV>
How can I do the ng-include conditionally in angularJS?
For example I only want to include something if, the variable x
is set to true
.
<div ng-include="/partial.html"></div>
解决方案
If you are using Angular v1.1.5 or later, you can also use ng-if:
<div ng-if="x" ng-include="'/partial.html'"></div>
If you have any older version:
Use ng-switch:
<div ng-switch on="x">
<div ng-switch-when="true" ng-include="'/partial.html'"></div>
</div>
这篇关于有条件的NG-包括angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文