简体   繁体   English

使用ng-show和ng-hide添加和删除模板

[英]adding and removing a template using ng-show and ng-hide

Can I use ng-show and ng-hide to display/hide a html template. 我可以使用ng-show和ng-hide来显示/隐藏html模板。 If that template is different html file. 如果该模板是其他html文件。 I am trying to split my html file into two parts and show/hide it on a event. 我正在尝试将html文件分为两部分,并在事件中显示/隐藏它。

It would be better is you use ng-if instead ng-show as it would save one html template request. 最好使用ng-if而不是ng-show,因为这样可以节省一个html模板请求。

<div ng-if="some_condition">
    <div ng-include="'template1_path.htm'"></div>
</div>

<div ng-if="!some_condition">
    <div ng-include="'template2_path.html'"></div>
</div>

Yes you can use ngShow/ngHide in conjunction with ngInclude : 是的,您可以将ngShow/ngHidengInclude结合使用:

<div ng-show="some_condition">
    <div ng-include="template1_path">
    </div>
</div>

<div ng-show="!some_condition">
    <div ng-include="template2_path">
    </div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM