angularjs 中的条件 ng-include [英] Conditional ng-include in angularjs

查看:22
本文介绍了angularjs 中的条件 ng-include的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 angularJS 中有条件地执行 ng-include?

例如,如果变量 x 设置为 true,我只想包含一些内容.

解决方案

如果您使用的是 Angular v1.1.5 或更高版本,您也可以使用 ng-if:

<div ng-if="x" ng-include="'/partial.html'"></div>

<小时>

如果您有任何旧版本:

使用ng-switch:

<div ng-switch-when="true" ng-include="'/partial.html'"></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>

Fiddle

这篇关于angularjs 中的条件 ng-include的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆