在 angular's ng-switch 中使用 html 模板 [英] Using html templates in angular's ng-switch

查看:29
本文介绍了在 angular's ng-switch 中使用 html 模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个随用户点击而移动的交互式菜单".我想知道是否有办法在 ng-switch 中包含 html 模板,因为每个开关"中的所有逻辑都不同 - 这将导致巨大的 html 文件.

<div ng-switch-when="1" ><h1>1</h1>

<div ng-switch-when="2"><h1>2</h1>

解决方案

使用 ngInclude:

<div ng-switch-when="1" ><ng-include src="'template1.html'"></ng-include>

<div ng-switch-when="2"><ng-include src="'template2.html'"></ng-include>

注意:如果您对路径进行硬编码,请不要忘记使用包含在双引号中的单引号.

Im making an 'interactive menu' that moves along with user clicks. Im wondering if there is a way to include html templates in ng-switch, since all the logic is different in each 'switch' - it will result in huge html files.

<div class="content" ng-switch on="selection">
 <div ng-switch-when="1" >
   <h1>1</h1>
 </div>
 <div ng-switch-when="2">
   <h1>2</h1>       
 </div>
</div>

解决方案

Use ngInclude:

<div class="content" ng-switch on="selection">
    <div ng-switch-when="1" >
        <ng-include src="'template1.html'"></ng-include>
    </div>
    <div ng-switch-when="2">
        <ng-include src="'template2.html'"></ng-include>
    </div>
</div>

Note: Dont forget to use single quotes wrapped inside the double quotes if you are hard-coding the path.

这篇关于在 angular&amp;#39;s ng-switch 中使用 html 模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆